diff --git a/src/storage/repo-storage.cpp b/src/storage/repo-storage.cpp
new file mode 100644
index 0000000..381ccaa
--- /dev/null
+++ b/src/storage/repo-storage.cpp
@@ -0,0 +1,116 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014,  Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "repo-storage.hpp"
+#include "../../build/src/config.hpp"
+#include <istream>
+
+namespace repo {
+
+static void
+insertItemToIndex(Index* index, const Storage::ItemMeta& item)
+{
+  index->insert(item.fullName, item.id, item.keyLocatorHash);
+}
+
+RepoStorage::RepoStorage(const int64_t& nMaxPackets, Storage& store)
+  : m_index(nMaxPackets)
+  , m_storage(store)
+{
+}
+
+void
+RepoStorage::initialize()
+{
+  m_storage.fullEnumerate(bind(&insertItemToIndex, &m_index, _1));
+}
+
+bool
+RepoStorage::insertData(const Data& data)
+{
+   bool isExist = m_index.hasData(data);
+   if (isExist)
+     throw Error("The Entry Has Already In the Skiplist. Cannot be Inserted!");
+   int64_t id = m_storage.insert(data);
+   if (id == -1)
+     return false;
+   return m_index.insert(data, id);
+}
+
+ssize_t
+RepoStorage::deleteData(const Name& name)
+{
+  bool hasError = false;
+  std::pair<int64_t,ndn::Name> idName = m_index.find(name);
+  if (idName.first == 0)
+    return false;
+  int64_t count = 0;
+  while (idName.first != 0) {
+    bool resultDb = m_storage.erase(idName.first);
+    bool resultIndex = m_index.erase(idName.second); //full name
+    if (resultDb && resultIndex)
+      count++;
+    else
+      hasError = true;
+    idName = m_index.find(name);
+  }
+  if (hasError)
+    return -1;
+  else
+    return count;
+}
+
+ssize_t
+RepoStorage::deleteData(const Interest& interest)
+{
+  Interest interestDelete = interest;
+  interestDelete.setChildSelector(0);  //to disable the child selector in delete handle
+  int64_t count = 0;
+  bool hasError = false;
+  std::pair<int64_t,ndn::Name> idName = m_index.find(interestDelete);
+  while (idName.first != 0) {
+    bool resultDb = m_storage.erase(idName.first);
+    bool resultIndex = m_index.erase(idName.second); //full name
+    if (resultDb && resultIndex)
+      count++;
+    else
+      hasError = true;
+    idName = m_index.find(interestDelete);
+  }
+  if (hasError)
+    return -1;
+  else
+    return count;
+}
+
+shared_ptr<Data>
+RepoStorage::readData(const Interest& interest) const
+{
+  std::pair<int64_t,ndn::Name> idName = m_index.find(interest);
+  if (idName.first != 0) {
+    shared_ptr<Data> data = m_storage.read(idName.first);
+    if (data) {
+      return data;
+    }
+  }
+  return shared_ptr<Data>();
+}
+
+
+} // namespace repo
diff --git a/src/storage/repo-storage.hpp b/src/storage/repo-storage.hpp
new file mode 100644
index 0000000..ed0ce9d
--- /dev/null
+++ b/src/storage/repo-storage.hpp
@@ -0,0 +1,100 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014,  Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef REPO_STORAGE_REPO_STORE_HPP
+#define REPO_STORAGE_REPO_STORE_HPP
+
+#include "../common.hpp"
+#include "storage.hpp"
+#include "index.hpp"
+#include "../repo-command-parameter.hpp"
+
+#include <ndn-cxx/exclude.hpp>
+
+#include <queue>
+
+namespace repo {
+
+/**
+ *  @brief  RepoStorage handles the storage part of whole repo,
+ *          including index and database
+ */
+class RepoStorage : noncopyable
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
+public:
+  RepoStorage(const int64_t& nMaxPackets, Storage& store);
+
+  /**
+   *  @brief  rebuild index from database
+   */
+  void
+  initialize();
+
+  /**
+   *  @brief  insert data into repo
+   */
+  bool
+  insertData(const Data& data);
+
+  /**
+   *  @brief   delete data from repo
+   *  @param   name     used to find entry needed to be erased in repo
+   *  @return  if deletion in either index or database fail, return -1,
+   *           otherwise return the number of erased entries
+   */
+  ssize_t
+  deleteData(const Name& name);
+
+  /**
+   *  @brief   delete data from repo
+   *  @param   interest used to find entry needed to be erased in repo
+   *  @return  if deletion in either index or database fail, return -1,
+   *           otherwise return the number of erased entries
+   */
+  ssize_t
+  deleteData(const Interest& interest);
+
+  /**
+   *  @brief  read data from repo
+   *  @param   interest  used to request data
+   *  @return  std::pair<bool,shared_ptr<Data> >
+   */
+  shared_ptr<Data>
+  readData(const Interest& interest) const;
+
+private:
+  Index m_index;
+  Storage& m_storage;
+
+};
+
+} // namespace repo
+
+#endif // REPO_REPO_STORE_HPP
diff --git a/src/storage/skiplist.hpp b/src/storage/skiplist.hpp
index 1243a71..34c7c57 100644
--- a/src/storage/skiplist.hpp
+++ b/src/storage/skiplist.hpp
@@ -397,7 +397,7 @@
     m_head->prevs.resize(newLevel + 1, m_head);
     insertPositions.resize(newLevel + 1, m_head);
   }
-  for (int i = 0; i <= static_cast<int>(newLevel); i++) {
+  for (int i = 0; i <= newLevel; i++) {
     newNode->nexts[i] = insertPositions[i]->nexts[i];
     newNode->prevs[i] = insertPositions[i];
     insertPositions[i]->nexts[i] = newNode;
diff --git a/src/storage/sqlite-handle.cpp b/src/storage/sqlite-handle.cpp
deleted file mode 100644
index 5842947..0000000
--- a/src/storage/sqlite-handle.cpp
+++ /dev/null
@@ -1,853 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California.
- *
- * This file is part of NDN repo-ng (Next generation of NDN repository).
- * See AUTHORS.md for complete list of repo-ng authors and contributors.
- *
- * repo-ng is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.hpp"
-#include "sqlite-handle.hpp"
-#include <boost/filesystem.hpp>
-
-namespace repo {
-
-SqliteHandle::SqliteHandle(const string& dbPath)
-  : StorageHandle(STORAGE_METHOD_SQLITE)
-{
-  if (dbPath.empty()) {
-    std::cerr << "Create db file in local location [" << dbPath << "]. " << std::endl
-              << "You can assign the path using -d option" << std::endl;
-    m_dbPath = string("ndn_repo.db");
-  }
-  else {
-    boost::filesystem::path fsPath(dbPath);
-    boost::filesystem::file_status fsPathStatus = boost::filesystem::status(fsPath);
-    if (!boost::filesystem::is_directory(fsPathStatus)) {
-      if (!boost::filesystem::create_directory(boost::filesystem::path(fsPath))) {
-        throw Error("Folder '" + dbPath + "' does not exists and cannot be created");
-      }
-    }
-
-    m_dbPath = dbPath + "/ndn_repo.db";
-  }
-  initializeRepo();
-}
-
-void
-SqliteHandle::initializeRepo()
-{
-  char* errMsg = 0;
-
-  int rc = sqlite3_open_v2(m_dbPath.c_str(), &m_db,
-                           SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
-#ifdef DISABLE_SQLITE3_FS_LOCKING
-                           "unix-dotfile"
-#else
-                           0
-#endif
-                           );
-
-  if (rc == SQLITE_OK) {
-    sqlite3_exec(m_db, "CREATE TABLE NDN_REPO ("
-                      "name BLOB PRIMARY KEY, "
-                      "data BLOB, "
-                      "parentName BLOB, "
-                      "nChildren INTEGER);\n"
-                      "CREATE INDEX NdnRepoParentName ON NDN_REPO (parentName);\n"
-                      "CREATE INDEX NdnRepoData ON NDN_REPO (data);\n"
-                 , 0, 0, &errMsg);
-    // Ignore errors (when database already exists, errors are expected)
-  }
-  else {
-    std::cerr << "Database file open failure rc:" << rc << std::endl;
-    throw Error("Database file open failure");
-  }
-
-  Name rootName;
-  string sql = string("SELECT * FROM NDN_REPO WHERE name = ?;");
-
-  sqlite3_stmt* queryStmt = 0;
-
-  rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc == SQLITE_OK) {
-    if (sqlite3_bind_blob(queryStmt, 1, rootName.wireEncode().wire(),
-                          rootName.wireEncode().size(), 0) == SQLITE_OK) {
-      rc = sqlite3_step(queryStmt);
-      if (rc == SQLITE_ROW) {
-        std::cerr << "root has been created" << std::endl;
-      }
-      else if (rc == SQLITE_DONE) {
-        sqlite3_stmt* p2Stmt = 0;
-        sql = string("INSERT INTO NDN_REPO (name, data, parentName, nChildren) "
-                     " VALUES (?,    ?,    ?,     ?);");
-        rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &p2Stmt, 0);
-        if (rc == SQLITE_OK) {
-          if (sqlite3_bind_blob(p2Stmt, 1, rootName.wireEncode().wire(),
-                                rootName.wireEncode().size(), 0) == SQLITE_OK &&
-              sqlite3_bind_null(p2Stmt, 2) == SQLITE_OK &&
-              sqlite3_bind_null(p2Stmt, 3) == SQLITE_OK &&
-              sqlite3_bind_int(p2Stmt, 4, 0) == SQLITE_OK) {
-            rc = sqlite3_step(p2Stmt);;
-            if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
-              std::cerr << "Root name insert failure rc:" << rc << std::endl;
-              sqlite3_finalize(p2Stmt);
-              throw Error("Root name insert failure");
-            }
-          }
-          else {
-            std::cerr << "bind blob failure rc:" << rc << std::endl;
-            sqlite3_finalize(p2Stmt);
-            throw Error("bind blob failure");
-          }
-        }
-        else {
-          std::cerr << "p2Stmt prepared rc:" << rc << std::endl;
-          sqlite3_finalize(p2Stmt);
-          throw Error("p2Stmt prepared");
-        }
-        sqlite3_finalize(p2Stmt);
-      }
-      else {
-        std::cerr << "Database query failure rc:" << rc << std::endl;
-        sqlite3_finalize(queryStmt);
-        throw Error("Database query failure");
-      }
-    }
-    sqlite3_finalize(queryStmt);
-  }
-  sqlite3_exec(m_db, "PRAGMA synchronous = OFF", 0, 0, &errMsg);
-  sqlite3_exec(m_db, "PRAGMA journal_mode = WAL", 0, 0, &errMsg);
-}
-
-SqliteHandle::~SqliteHandle()
-{
-  sqlite3_close(m_db);
-}
-
-
-//Temporarily assigned the datatype of every component. needs to be further discussed
-
-bool
-SqliteHandle::insertData(const Data& data)
-{
-  Name name = data.getName();
-
-  if (name.empty()) {
-    std::cerr << "name is empty" << std::endl;
-    return false;
-  }
-
-  int rc = 0;
-
-  string updateSql2 = string("UPDATE NDN_REPO SET data = ? WHERE name = ?;");
-  //std::cerr << "update" << std::endl;
-  sqlite3_stmt* update2Stmt = 0;
-  if (sqlite3_prepare_v2(m_db, updateSql2.c_str(), -1, &update2Stmt, 0) != SQLITE_OK) {
-    sqlite3_finalize(update2Stmt);
-    std::cerr << "update sql2 not prepared" << std::endl;
-    throw Error("update sql2 not prepared");
-  }
-  if (sqlite3_bind_blob(update2Stmt, 1,
-                        data.wireEncode().wire(),
-                        data.wireEncode().size(), 0) == SQLITE_OK &&
-      sqlite3_bind_blob(update2Stmt, 2,
-                        name.wireEncode().wire(),
-                        name.wireEncode().size(), 0) == SQLITE_OK) {
-    rc = sqlite3_step(update2Stmt);
-    sqlite3_finalize(update2Stmt);
-    if (rc != SQLITE_DONE) {
-      return false;
-    }
-    //what error??
-    //std::cerr << "update rc:" << rc << std::endl;
-    /// \todo Do something with rc
-  }
-  int changeCount = sqlite3_changes(m_db);
-  //std::cerr << "changeCount: " << changeCount << std::endl;
-  if (changeCount > 0) {
-    return true;
-  }
-
-  sqlite3_stmt* insertStmt = 0;
-  sqlite3_stmt* updateStmt = 0;
-  string insertSql = string("INSERT INTO NDN_REPO (name, data, parentName, nChildren) "
-                            "VALUES (?, ?, ?, ?)");
-  string updateSql = string("UPDATE NDN_REPO SET nChildren = nChildren + 1 WHERE name = ?");
-
-  Name rootName;
-
-
-  if (sqlite3_prepare_v2(m_db, insertSql.c_str(), -1, &insertStmt, 0) != SQLITE_OK) {
-    sqlite3_finalize(insertStmt);
-    std::cerr << "insert sql not prepared" << std::endl;
-  }
-  if (sqlite3_prepare_v2(m_db, updateSql.c_str(), -1, &updateStmt, 0) != SQLITE_OK) {
-    sqlite3_finalize(updateStmt);
-    std::cerr << "update sql not prepared" << std::endl;
-    throw Error("update sql not prepared");
-  }
-
-  //Insert and read the prefix
-  Name parentName = name;
-  Name grandName;
-  do {
-    parentName = parentName.getPrefix(-1);
-    if (!hasName(parentName)) {
-      grandName = parentName.getPrefix(-1);
-      if (sqlite3_bind_blob(insertStmt, 1,
-                            parentName.wireEncode().wire(),
-                            parentName.wireEncode().size(), 0) == SQLITE_OK &&
-          sqlite3_bind_null(insertStmt, 2) == SQLITE_OK &&
-          sqlite3_bind_blob(insertStmt, 3,
-                            grandName.wireEncode().wire(),
-                            grandName.wireEncode().size(), 0) == SQLITE_OK &&
-          sqlite3_bind_int(insertStmt, 4, 1) == SQLITE_OK) {
-        rc = sqlite3_step(insertStmt);
-        if (rc == SQLITE_CONSTRAINT) {
-          std::cerr << "Insert parent prefix failed" << std::endl;
-          sqlite3_finalize(insertStmt);
-          throw Error("Insert parent prefix failed");
-        }
-        sqlite3_reset(insertStmt);
-      }
-    }
-    else {
-      break;
-    }
-  } while (!parentName.empty());
-
-  //The existed parent nChildren + 1
-
-  if (sqlite3_bind_blob(updateStmt, 1, parentName.wireEncode().wire(),
-                        parentName.wireEncode().size(), 0) == SQLITE_OK) {
-    rc = sqlite3_step(updateStmt);
-    if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
-      std::cerr << "update error rc:" << rc << std::endl;
-      sqlite3_finalize(updateStmt);
-      sqlite3_finalize(insertStmt);
-      throw Error("update error");
-    }
-    sqlite3_reset(updateStmt);
-  }
-
-  //Insert the name and the data, if this data name exists update, else insert data
-
-  parentName = name.getPrefix(-1);
-  sqlite3_reset(insertStmt);
-  if (sqlite3_bind_blob(insertStmt, 1,
-                        name.wireEncode().wire(),
-                        name.wireEncode().size(), 0) == SQLITE_OK &&
-      sqlite3_bind_blob(insertStmt, 2,
-                        data.wireEncode().wire(),
-                        data.wireEncode().size(), 0) == SQLITE_OK &&
-      sqlite3_bind_blob(insertStmt, 3,
-                        parentName.wireEncode().wire(),
-                        parentName.wireEncode().size(), 0) == SQLITE_OK &&
-      sqlite3_bind_int(insertStmt, 4, 0) == SQLITE_OK) {
-    rc = sqlite3_step(insertStmt);
-    //std::cerr << "insert rc:" << rc << std::endl;
-    //std::cerr << "insert the data: " << data.wireEncode().wire() << std::endl;
-    if (rc == SQLITE_CONSTRAINT) {
-      std::cerr << "The name of the data has existed!" << std::endl;
-      sqlite3_finalize(insertStmt);
-      return false;
-    }
-  }
-
-  sqlite3_finalize(updateStmt);
-  sqlite3_finalize(insertStmt);
-  return true;
-}
-
-bool
-SqliteHandle::deleteData(const Name& name)
-{
-  sqlite3_stmt* queryStmt = 0;
-  sqlite3_stmt* deleteStmt = 0;
-  sqlite3_stmt* updateStmt = 0;
-  sqlite3_stmt* update2Stmt = 0;
-
-  string querySql = string("SELECT * from NDN_REPO where name = ?;");
-  string deleteSql = string("DELETE from NDN_REPO where name = ?;");
-
-  string updateSql = string("UPDATE NDN_REPO SET nChildren = nChildren - 1 WHERE name = ?;");
-  string updateSql2 = string("UPDATE NDN_REPO SET data = NULL WHERE name = ?;");
-
-  int rc = sqlite3_prepare_v2(m_db, querySql.c_str(), -1, &queryStmt, 0);
-  Name tmpName = name;
-  int nChildren = -1;
-  if (sqlite3_prepare_v2(m_db, deleteSql.c_str(), -1, &deleteStmt, 0) != SQLITE_OK) {
-    sqlite3_finalize(deleteStmt);
-    std::cerr << "delete statement prepared failed" << std::endl;
-    throw Error("delete statement prepared failed");
-  }
-  if (sqlite3_prepare_v2(m_db, updateSql.c_str(), -1, &updateStmt, 0) != SQLITE_OK) {
-    sqlite3_finalize(updateStmt);
-    std::cerr << "delete update prepared failed" << std::endl;
-    throw Error("delete update prepared failed");
-  }
-  if (rc == SQLITE_OK) {
-    if (sqlite3_bind_blob(queryStmt, 1,
-                          tmpName.wireEncode().wire(),
-                          tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-      rc = sqlite3_step(queryStmt);
-      if (rc == SQLITE_ROW) {
-        nChildren = sqlite3_column_int(queryStmt, 3);
-      }
-      else {
-        std::cerr << "Database query no such name or failure rc:" << rc << std::endl;
-        sqlite3_finalize(queryStmt);
-        return false;
-      }
-    }
-    if (nChildren > 0) {
-      //update internal node, so just update and return
-      if (sqlite3_prepare_v2(m_db, updateSql2.c_str(), -1, &update2Stmt, 0) != SQLITE_OK) {
-        sqlite3_finalize(update2Stmt);
-        std::cerr << "delete update prepared failed" << std::endl;
-        throw Error("delete update prepared failed");
-      }
-      if (sqlite3_bind_blob(update2Stmt, 1,
-                            tmpName.wireEncode().wire(),
-                            tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-        rc = sqlite3_step(update2Stmt);
-        std::cerr << "deleteData update" << std::endl;
-      }
-      else {
-        std::cerr << "delete bind error" << std::endl;
-        sqlite3_finalize(update2Stmt);
-        throw Error("delete bind error");
-      }
-      return true;
-    }
-    else {
-      //Delete the leaf node
-      if (sqlite3_bind_blob(deleteStmt, 1,
-                            tmpName.wireEncode().wire(),
-                            tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-        rc = sqlite3_step(deleteStmt);
-        if (rc != SQLITE_DONE && rc !=SQLITE_ROW) {
-          std::cerr << "leaf node delete error rc:" << rc << std::endl;
-          sqlite3_finalize(deleteStmt);
-          throw Error("leaf node delete error");
-        }
-      }
-      else {
-        std::cerr << "delete bind error" << std::endl;
-        sqlite3_finalize(deleteStmt);
-        throw Error("delete bind error");
-      }
-      sqlite3_reset(deleteStmt);
-    }
-    queryStmt = 0;
-    rc = sqlite3_prepare_v2(m_db, querySql.c_str(), -1, &queryStmt, 0);
-    if (rc != SQLITE_OK) {
-      std::cerr << "prepare error" << std::endl;
-      sqlite3_finalize(queryStmt);
-      throw Error("prepare error");
-    }
-    //read prefix if nChildren is 0 and data is 0
-    int dataSize = 0;
-    do {
-      tmpName = tmpName.getPrefix(-1);
-      if (sqlite3_bind_blob(queryStmt, 1,
-                            tmpName.wireEncode().wire(),
-                            tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-        rc = sqlite3_step(queryStmt);
-        if (rc == SQLITE_ROW) {
-          nChildren = sqlite3_column_int(queryStmt, 3);
-          dataSize = sqlite3_column_bytes(queryStmt, 1);
-        }
-        else {
-          std::cerr << "Database query no such name or failure rc:" << rc << std::endl;
-          sqlite3_finalize(queryStmt);
-          return false;
-        }
-        if (nChildren == 1 && !tmpName.empty() && dataSize == 0) {
-          //Delete this internal node
-          if (sqlite3_bind_blob(deleteStmt, 1,
-                                tmpName.wireEncode().wire(),
-                                tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-            rc = sqlite3_step(deleteStmt);
-            if (rc != SQLITE_DONE && rc !=SQLITE_ROW) {
-              std::cerr << "internal node delete error rc:" << rc << std::endl;
-              sqlite3_finalize(deleteStmt);
-              throw Error("internal node delete error");
-            }
-          }
-          else {
-            std::cerr << "delete bind error" << std::endl;
-            sqlite3_finalize(deleteStmt);
-            throw Error("delete bind error");
-          }
-          sqlite3_reset(deleteStmt);
-        }
-        else {
-          //nChildren - 1
-          if (sqlite3_bind_blob(updateStmt, 1,
-                                tmpName.wireEncode().wire(),
-                                tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-            rc = sqlite3_step(updateStmt);
-            if (rc != SQLITE_DONE && rc !=SQLITE_ROW) {
-              std::cerr << "internal node nChildren update error rc:" << rc << std::endl;
-              sqlite3_finalize(updateStmt);
-              throw Error("internal node nChildren update error");
-            }
-          }
-          else {
-            std::cerr << "update bind error" << std::endl;
-            sqlite3_finalize(updateStmt);
-            throw Error("update bind error");
-          }
-          sqlite3_reset(updateStmt);
-          break;
-        }
-      }
-      else {
-        std::cerr << "query bind error" << std::endl;
-        sqlite3_finalize(queryStmt);
-        throw Error("query bind error");
-      }
-      sqlite3_reset(queryStmt);
-    } while (!tmpName.empty());
-
-  }
-  else {
-    std::cerr << "query prepared failure rc:" << rc << std::endl;
-    sqlite3_finalize(queryStmt);
-    throw Error("query prepared failure");
-  }
-  return true;
-}
-
-bool
-SqliteHandle::readData(const Interest& interest, Data& data)
-{
-  vector<Name> names;
-  Name resultName;
-  if (!interest.hasSelectors()) {
-    return readDataPlain(interest.getName(), data);
-  }
-  else {
-    if (readNameSelector(interest, names)) {
-      if (names.empty())
-        return false;
-      if (!filterNameChild(interest.getName(), interest.getChildSelector(), names, resultName)) {
-        return false;
-      }
-    }
-    return readData(resultName, data);
-  }
-}
-
-// This function is the first version of data read following longest prefix match.
-// It will return the leftmost data
-bool
-SqliteHandle::readDataPlain(const Name& name, Data& data)
-{
-  vector<Name> names;
-  Name resultName;
-  readDataName(name, names);
-  if (names.empty())
-    return false;
-  bool isOk = filterNameChild(name, 0, names, resultName);
-  if (isOk) {
-    return readData(resultName, data);
-  }
-  else
-  {
-    return false;
-  }
-}
-
-// retrieve all the leaf nodes of a subtree
-bool
-SqliteHandle::readDataName(const Name& name, vector<Name>& names) const
-{
-  if (name.empty()) {
-    std::cerr << "The name is empty" << std::endl;
-    return false;
-  }
-  Name tmpName = name;
-  //This queue is for internal node;
-  queue<Name> internalNames;
-
-  // Step 1. Check if the requested name corresponds to a leaf (data is not NULL)
-  string sql = string("SELECT * FROM NDN_REPO WHERE name = ? AND data IS NOT NULL;");
-  sqlite3_stmt* queryStmt = 0;
-  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc != SQLITE_OK)
-    throw Error("prepare error");
-
-  if (sqlite3_bind_blob(queryStmt, 1,
-                        tmpName.wireEncode().wire(),
-                        tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-    rc = sqlite3_step(queryStmt);
-    if (rc == SQLITE_ROW) {
-      int nChildren = sqlite3_column_int(queryStmt, 3);
-      Name elementName;
-      elementName.wireDecode(Block(sqlite3_column_blob(queryStmt, 0),
-                                   sqlite3_column_bytes(queryStmt, 0)));
-      names.push_back(elementName);
-      if (nChildren == 0) {
-        sqlite3_finalize(queryStmt);
-        return true;
-      }
-    }
-    else if (rc == SQLITE_DONE) {
-      // ignore
-    }
-    else {
-      std::cerr << "read error rc:" << rc << std::endl;
-      sqlite3_finalize(queryStmt);
-      throw Error("read error");
-    }
-  }
-  sqlite3_finalize(queryStmt);
-
-
-  // Step 2. Recursively find all data packets with the specified prefix
-  string psql = string("SELECT * FROM NDN_REPO WHERE parentName = ?;");
-  sqlite3_stmt* queryParentStmt = 0;
-  rc = sqlite3_prepare_v2(m_db, psql.c_str(), -1, &queryParentStmt, 0);
-  if (rc != SQLITE_OK)
-    throw Error("prepare error");
-
-  internalNames.push(tmpName);
-  while (!internalNames.empty()) {
-    tmpName = internalNames.front();
-    internalNames.pop();
-    if (sqlite3_bind_blob(queryParentStmt, 1,
-                          tmpName.wireEncode().wire(),
-                          tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-      while (true) {
-        rc = sqlite3_step(queryParentStmt);
-        if (rc == SQLITE_ROW) {
-          Name elementName;
-          elementName.wireDecode(Block(sqlite3_column_blob(queryParentStmt, 0),
-                                       sqlite3_column_bytes(queryParentStmt, 0)));
-          int nChildren = sqlite3_column_int(queryParentStmt, 3);
-          if (nChildren > 0) {
-            internalNames.push(elementName);
-          }
-          if (sqlite3_column_type(queryParentStmt, 1) != SQLITE_NULL) {
-            names.push_back(elementName);
-          }
-        }
-        else if (rc == SQLITE_DONE) {
-          break;
-        }
-        else {
-          std::cerr << "read error rc:" << rc << std::endl;
-          sqlite3_finalize(queryParentStmt);
-          throw Error("read error");
-        }
-      }
-      sqlite3_reset(queryParentStmt);
-    }
-    else {
-      std::cerr << "bind error" << std::endl;
-      sqlite3_finalize(queryParentStmt);
-      throw Error("bind error");
-    }
-  }
-  sqlite3_finalize(queryParentStmt);
-  return true;
-}
-
-bool
-SqliteHandle::readNameSelector(const Interest& interest, vector<Name>& names) const
-{
-  if (interest.getName().empty()) {
-    std::cerr << "The name of interest is empty" << std::endl;
-    return false;
-  }
-  Name tmpName = interest.getName();
-  //This queue is for internal node;
-  queue<Name> internalNames;
-
-  // Step 1. Check if the requested Data corresponds to a leaf (data is not NULL)
-  sqlite3_stmt* queryStmt = 0;
-  string sql = string("SELECT * FROM NDN_REPO WHERE name = ? AND data IS NOT NULL;");
-  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc != SQLITE_OK)
-    throw Error("prepare error");
-
-  if (sqlite3_bind_blob(queryStmt, 1,
-                        tmpName.wireEncode().wire(),
-                        tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-    rc = sqlite3_step(queryStmt);
-    if (rc == SQLITE_ROW) {
-      Data elementData;
-      elementData.wireDecode(Block(sqlite3_column_blob(queryStmt, 1),
-                                   sqlite3_column_bytes(queryStmt, 1)));
-      if (interest.matchesData(elementData)) {
-        names.push_back(elementData.getName());
-      }
-
-      int nChildren = sqlite3_column_int(queryStmt, 3);
-      if (nChildren == 0) {
-        sqlite3_finalize(queryStmt);
-        return true;
-      }
-    }
-    else if (rc == SQLITE_DONE) {
-      // ignore
-    }
-    else {
-      std::cerr << "read error rc:" << rc << std::endl;
-      sqlite3_finalize(queryStmt);
-      throw Error("read error");
-    }
-  }
-  sqlite3_finalize(queryStmt);
-
-  // Step 2. Recursively find all data packets that match the Interest
-  internalNames.push(tmpName);
-  sqlite3_stmt* queryParentStmt = 0;
-  string psql = string("SELECT * FROM NDN_REPO WHERE parentName = ?;");
-  rc = sqlite3_prepare_v2(m_db, psql.c_str(), -1, &queryParentStmt, 0);
-  if (rc != SQLITE_OK)
-    throw Error("prepare error");
-
-  while (!internalNames.empty()) {
-    tmpName = internalNames.front();
-    internalNames.pop();
-    if (sqlite3_bind_blob(queryParentStmt, 1,
-                          tmpName.wireEncode().wire(),
-                          tmpName.wireEncode().size(), 0) == SQLITE_OK) {
-      while (true) {
-        rc = sqlite3_step(queryParentStmt);
-        if (rc == SQLITE_ROW) {
-          if (sqlite3_column_type(queryParentStmt, 1) != SQLITE_NULL) {
-            Data elementData;
-            elementData.wireDecode(Block(sqlite3_column_blob(queryParentStmt, 1),
-                                         sqlite3_column_bytes(queryParentStmt, 1)));
-            if (interest.matchesData(elementData)) {
-              names.push_back(elementData.getName());
-            }
-          }
-
-          Name elementName;
-          elementName.wireDecode(Block(sqlite3_column_blob(queryParentStmt, 0),
-                                       sqlite3_column_bytes(queryParentStmt, 0)));
-
-          int nChildren = sqlite3_column_int(queryParentStmt, 3);
-          if (nChildren > 0) {
-            internalNames.push(elementName);
-          }
-        }
-        else if (rc == SQLITE_DONE) {
-          break;
-        }
-        else {
-          std::cerr << "read error rc:" << rc << std::endl;
-          sqlite3_finalize(queryParentStmt);
-          throw Error("read error");
-        }
-      }
-      sqlite3_reset(queryParentStmt);
-    }
-    else {
-      std::cerr << "bind error" << std::endl;
-      sqlite3_finalize(queryParentStmt);
-      throw Error("bind error");
-    }
-  }
-  sqlite3_finalize(queryParentStmt);
-  return true;
-}
-
-bool
-SqliteHandle::filterNameChild(const Name& name, int childSelector,
-                              const vector<Name>& names, Name& resultName)
-{
-  BOOST_ASSERT(!names.empty());
-
-  if (childSelector < 0) {
-    resultName = *names.begin();
-  }
-  else if (childSelector == 0) {
-    if (!names.empty()) {
-      resultName = *std::min_element(names.begin(), names.end());
-    }
-    else {
-      return false;
-    }
-  }
-  else if (childSelector == 1) {
-    if (!names.empty()) {
-      resultName = *std::max_element(names.begin(), names.end());
-    }
-    else {
-      return false;
-    }
-  }
-  else {
-    std::cerr << "Unknown ChildSelector specified" << std::endl;
-    return false;
-  }
-  return true;
-}
-
-bool
-SqliteHandle::readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names)
-{
-  if (selectors.empty()) {
-    if (hasName(name)) {
-      names.push_back(name);
-    }
-    return true;
-  }
-  else {
-    Interest interest(name);
-    interest.setSelectors(selectors);
-    readNameSelector(interest, names);
-    if (names.empty())
-      return false;
-    if (selectors.getChildSelector() >= 0) {
-      Name resultName;
-      if (!filterNameChild(name, selectors.getChildSelector(), names, resultName))
-        return false;
-      names.clear();
-      names.push_back(resultName);
-      return true;
-    }
-    else {
-      return true;
-    }
-  }
-}
-
-bool
-SqliteHandle::readData(const Name& name, Data& data)
-{
-  sqlite3_stmt* queryStmt = 0;
-  string sql = string("SELECT * FROM NDN_REPO WHERE name = ? AND data IS NOT NULL;");
-  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc == SQLITE_OK) {
-    if (sqlite3_bind_blob(queryStmt, 1,
-                          name.wireEncode().wire(),
-                          name.wireEncode().size(), 0) == SQLITE_OK) {
-      rc = sqlite3_step(queryStmt);
-      if (rc == SQLITE_ROW) {
-        data.wireDecode(Block(sqlite3_column_blob(queryStmt, 1),
-                              sqlite3_column_bytes(queryStmt, 1)));
-        sqlite3_finalize(queryStmt);
-        return true;
-      }
-      else if (rc == SQLITE_DONE) {
-        return false;
-      }
-      else {
-        std::cerr << "Database query failure rc:" << rc << std::endl;
-        sqlite3_finalize(queryStmt);
-        throw Error("Database query failure");
-      }
-    }
-    sqlite3_finalize(queryStmt);
-  }
-  return true;
-}
-
-
-//This is the exact name query in database.
-bool
-SqliteHandle::hasName(const Name& name)
-{
-  sqlite3_stmt* queryStmt = 0;
-  string sql = string("select * from NDN_REPO where name = ?;");
-  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc == SQLITE_OK) {
-    if (sqlite3_bind_blob(queryStmt, 1,
-                          name.wireEncode().wire(),
-                          name.wireEncode().size(), 0) == SQLITE_OK) {
-      rc = sqlite3_step(queryStmt);
-      if (rc == SQLITE_ROW) {
-        sqlite3_finalize(queryStmt);
-        return true;
-      }
-      else if (rc == SQLITE_DONE) {
-        sqlite3_finalize(queryStmt);
-        return false;
-      }
-      else {
-        std::cerr << "Database query failure rc:" << rc << std::endl;
-        sqlite3_finalize(queryStmt);
-        return false;
-      }
-    }
-    sqlite3_finalize(queryStmt);
-  }
-  return true;
-}
-
-//This is the exact parent name query in database.
-bool
-SqliteHandle::hasParentName(const Name& parentName) const
-{
-  sqlite3_stmt* queryStmt = 0;
-  string sql = string("SELECT * FROM NDN_REPO WHERE parentName = ?;");
-  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc == SQLITE_OK) {
-    if (sqlite3_bind_blob(queryStmt, 1,
-                          parentName.wireEncode().wire(),
-                          parentName.wireEncode().size(), 0) == SQLITE_OK) {
-      rc = sqlite3_step(queryStmt);
-      if (rc == SQLITE_ROW) {
-        sqlite3_finalize(queryStmt);
-        return true;
-      }
-      else if (rc == SQLITE_DONE) {
-        sqlite3_finalize(queryStmt);
-        return false;
-      }
-      else {
-        std::cerr << "Database query failure rc:" << rc << std::endl;
-        sqlite3_finalize(queryStmt);
-        return false;
-      }
-    }
-    sqlite3_finalize(queryStmt);
-  }
-  return true;
-}
-
-size_t
-SqliteHandle::size()
-{
-  sqlite3_stmt* queryStmt = 0;
-  string sql("SELECT count(*) FROM NDN_REPO WHERE data IS NOT NULL");
-  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
-  if (rc != SQLITE_OK)
-    {
-      std::cerr << "Database query failure rc:" << rc << std::endl;
-      sqlite3_finalize(queryStmt);
-      throw Error("Database query failure");
-    }
-
-  rc = sqlite3_step(queryStmt);
-  if (rc != SQLITE_ROW)
-    {
-      std::cerr << "Database query failure rc:" << rc << std::endl;
-      sqlite3_finalize(queryStmt);
-      throw Error("Database query failure");
-    }
-
-  size_t nDatas = static_cast<size_t>(sqlite3_column_int64(queryStmt, 0));
-  return nDatas;
-}
-
-} //namespace repo
diff --git a/src/storage/sqlite-handle.hpp b/src/storage/sqlite-handle.hpp
deleted file mode 100644
index a0fbb1c..0000000
--- a/src/storage/sqlite-handle.hpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California.
- *
- * This file is part of NDN repo-ng (Next generation of NDN repository).
- * See AUTHORS.md for complete list of repo-ng authors and contributors.
- *
- * repo-ng is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef REPO_STORAGE_SQLITE_HANDLE_HPP
-#define REPO_STORAGE_SQLITE_HANDLE_HPP
-
-#include "storage-handle.hpp"
-
-#include <string>
-#include <iostream>
-#include <sqlite3.h>
-#include <stdlib.h>
-#include <vector>
-#include <queue>
-#include <algorithm>
-
-namespace repo {
-
-using std::queue;
-
-class SqliteHandle : public StorageHandle
-{
-public:
-  class Error : public StorageHandle::Error
-  {
-  public:
-    explicit
-    Error(const std::string& what)
-      : StorageHandle::Error(what)
-    {
-    }
-  };
-
-  SqliteHandle();
-
-  explicit
-  SqliteHandle(const string& dbPath);
-
-  virtual
-  ~SqliteHandle();
-
-
-  // from StorageHandle
-
-  virtual bool
-  insertData(const Data& data);
-
-  virtual bool
-  deleteData(const Name& name);
-
-  virtual bool
-  readData(const Interest& interest, Data& data);
-
-  virtual bool
-  hasName(const Name& name);
-
-  virtual bool
-  readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names);
-
-  virtual size_t
-  size();
-
-private:
-  void
-  initializeRepo();
-
-  /**
-  * @brief find data with the exact name matched
-  * @param[out] data Data matching Interest.
-  * @return if no data or something is wrong, return false
-  */
-  bool
-  readData(const Name& name, Data& data);
-
-  /**
-  * @brief check whether there is one row with this parentName = parentName in database
-  * @return if no data or something is wrong, return false.
-  */
-  bool
-  hasParentName(const Name& parentName) const;
-
-  /**
-  * @brief This function is for no selector, it will reply the leftmost data
-  * @param[out] data Data matching Interest.
-  * @return if no data or something is wrong, return false.
-  */
-  bool
-  readDataPlain(const Name& name, Data& data);
-
-  /**
-  * @brief  read data with this prefix or name
-  * @param name indicates name or prefix of interest
-  * @param[out] names is vector to contain the result of this function.
-  * @return success return true, error return false
-  */
-  bool
-  readDataName(const Name& name, vector<Name>& names) const;
-
-  /**
-  * @brief  read data with this prefix or name and selectors including  MinSuffixComponents,
-  * MaxSuffixComponents, PublisherPublicKeyLocator, and Exclude.
-  * This method does not consider ChildSelector and MustBeFresh.
-  *
-  * @param name indicates name or prefix of interest
-  * @param[out] names is vector to contain the result of this function.
-  * @return success return true, error return false
-  */
-  bool
-  readNameSelector(const Interest& interest, vector<Name>& names) const;
-
-  /**
-  * @brief ChildSelector filter
-  * @param names list of candidate names for ChildSelector filter
-  * @param[out] resultName is the result of selected name
-  * @return success return true, error return false
-  */
-  bool
-  filterNameChild(const Name& name, int childSelector,
-                  const vector<Name>& names, Name& resultName);
-
-private:
-  sqlite3* m_db;
-  string m_dbPath;
-};
-
-} // namespace repo
-
-#endif // REPO_STORAGE_SQLITE_HANDLE_HPP
diff --git a/src/storage/sqlite-storage.cpp b/src/storage/sqlite-storage.cpp
new file mode 100644
index 0000000..78b1792
--- /dev/null
+++ b/src/storage/sqlite-storage.cpp
@@ -0,0 +1,286 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014,  Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "../../build/src/config.hpp"
+#include "sqlite-storage.hpp"
+#include "index.hpp"
+#include <boost/filesystem.hpp>
+#include <istream>
+
+namespace repo {
+
+SqliteStorage::SqliteStorage(const string& dbPath)
+  : m_size(0)
+{
+  if (dbPath.empty()) {
+    std::cerr << "Create db file in local location [" << dbPath << "]. " << std::endl
+              << "You can assign the path using -d option" << std::endl;
+    m_dbPath = string("ndn_repo.db");
+  }
+  else {
+    boost::filesystem::path fsPath(dbPath);
+    boost::filesystem::file_status fsPathStatus = boost::filesystem::status(fsPath);
+    if (!boost::filesystem::is_directory(fsPathStatus)) {
+      if (!boost::filesystem::create_directory(boost::filesystem::path(fsPath))) {
+        throw Error("Folder '" + dbPath + "' does not exists and cannot be created");
+      }
+    }
+
+    m_dbPath = dbPath + "/ndn_repo.db";
+  }
+  initializeRepo();
+}
+
+
+void
+SqliteStorage::initializeRepo()
+{
+  char* errMsg = 0;
+
+  int rc = sqlite3_open_v2(m_dbPath.c_str(), &m_db,
+                           SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
+#ifdef DISABLE_SQLITE3_FS_LOCKING
+                           "unix-dotfile"
+#else
+                           0
+#endif
+                           );
+
+  if (rc == SQLITE_OK) {
+    sqlite3_exec(m_db, "CREATE TABLE NDN_REPO ("
+                      "id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
+                      "name BLOB, "
+                      "data BLOB, "
+                      "keylocatorHash BLOB);\n "
+                 , 0, 0, &errMsg);
+    // Ignore errors (when database already exists, errors are expected)
+  }
+  else {
+    std::cerr << "Database file open failure rc:" << rc << std::endl;
+    throw Error("Database file open failure");
+  }
+  sqlite3_exec(m_db, "PRAGMA synchronous = OFF", 0, 0, &errMsg);
+  sqlite3_exec(m_db, "PRAGMA journal_mode = WAL", 0, 0, &errMsg);
+}
+
+SqliteStorage::~SqliteStorage()
+{
+  sqlite3_close(m_db);
+}
+
+void
+SqliteStorage::fullEnumerate(const ndn::function
+                             <void(const Storage::ItemMeta)>& f)
+{
+  sqlite3_stmt* m_stmt = 0;
+  int rc = SQLITE_DONE;
+  string sql = string("SELECT id, name, keylocatorHash FROM NDN_REPO;");
+  rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &m_stmt, 0);
+  if (rc != SQLITE_OK)
+    throw Error("Initiation Read Entries from Database Prepare error");
+  int entryNumber = 0;
+  while (true) {
+    rc = sqlite3_step(m_stmt);
+    if (rc == SQLITE_ROW) {
+
+      ItemMeta item;
+      item.fullName.wireDecode(Block(sqlite3_column_blob(m_stmt, 1),
+                                     sqlite3_column_bytes(m_stmt, 1)));
+      item.id = sqlite3_column_int(m_stmt, 0);
+      item.keyLocatorHash = make_shared<const ndn::Buffer>
+        (ndn::Buffer(sqlite3_column_blob(m_stmt, 3), sqlite3_column_bytes(m_stmt, 3)));
+
+      try {
+        f(item);
+      }
+      catch (...){
+        sqlite3_finalize(m_stmt);
+        throw;
+      }
+      entryNumber++;
+    }
+    else if (rc == SQLITE_DONE) {
+      sqlite3_finalize(m_stmt);
+      break;
+    }
+    else {
+      std::cerr << "Initiation Read Entries rc:" << rc << std::endl;
+      sqlite3_finalize(m_stmt);
+      throw Error("Initiation Read Entries error");
+    }
+  }
+  m_size = entryNumber;
+}
+
+int64_t
+SqliteStorage::insert(const Data& data)
+{
+  Name name = data.getName();
+
+  Index::Entry entry(data, 0); //the id is not used
+  int64_t id = -1;
+  if (name.empty()) {
+    std::cerr << "name is empty" << std::endl;
+    return -1;
+  }
+
+  int rc = 0;
+
+  sqlite3_stmt* insertStmt = 0;
+
+  string insertSql = string("INSERT INTO NDN_REPO (id, name, data, keylocatorHash) "
+                            "VALUES (?, ?, ?, ?)");
+
+  if (sqlite3_prepare_v2(m_db, insertSql.c_str(), -1, &insertStmt, 0) != SQLITE_OK) {
+    sqlite3_finalize(insertStmt);
+    std::cerr << "insert sql not prepared" << std::endl;
+  }
+  //Insert
+  if (sqlite3_bind_null(insertStmt, 1) == SQLITE_OK &&
+      sqlite3_bind_blob(insertStmt, 2,
+                        entry.getName().wireEncode().wire(),
+                        entry.getName().wireEncode().size(), 0) == SQLITE_OK &&
+      sqlite3_bind_blob(insertStmt, 3,
+                        data.wireEncode().wire(),
+                        data.wireEncode().size(),0 ) == SQLITE_OK &&
+      sqlite3_bind_blob(insertStmt, 4,
+                        (const void*)&(*entry.getKeyLocatorHash()),
+                        ndn::crypto::SHA256_DIGEST_SIZE,0) == SQLITE_OK) {
+    rc = sqlite3_step(insertStmt);
+    if (rc == SQLITE_CONSTRAINT) {
+      std::cerr << "Insert  failed" << std::endl;
+      sqlite3_finalize(insertStmt);
+      throw Error("Insert failed");
+     }
+    sqlite3_reset(insertStmt);
+     m_size++;
+     id = sqlite3_last_insert_rowid(m_db);
+  }
+  else {
+    throw Error("Some error with insert");
+  }
+
+  sqlite3_finalize(insertStmt);
+  return id;
+}
+
+
+bool
+SqliteStorage::erase(const int64_t id)
+{
+  sqlite3_stmt* deleteStmt = 0;
+
+  string deleteSql = string("DELETE from NDN_REPO where id = ?;");
+
+  if (sqlite3_prepare_v2(m_db, deleteSql.c_str(), -1, &deleteStmt, 0) != SQLITE_OK) {
+    sqlite3_finalize(deleteStmt);
+    std::cerr << "delete statement prepared failed" << std::endl;
+    throw Error("delete statement prepared failed");
+  }
+
+  if (sqlite3_bind_int64(deleteStmt, 1, id) == SQLITE_OK) {
+    int rc = sqlite3_step(deleteStmt);
+    if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
+      std::cerr << " node delete error rc:" << rc << std::endl;
+      sqlite3_finalize(deleteStmt);
+      throw Error(" node delete error");
+    }
+    if (sqlite3_changes(m_db) != 1)
+      return false;
+    m_size--;
+  }
+  else {
+    std::cerr << "delete bind error" << std::endl;
+    sqlite3_finalize(deleteStmt);
+    throw Error("delete bind error");
+  }
+  sqlite3_finalize(deleteStmt);
+  return true;
+}
+
+
+shared_ptr<Data>
+SqliteStorage::read(const int64_t id)
+{
+  sqlite3_stmt* queryStmt = 0;
+  string sql = string("SELECT * FROM NDN_REPO WHERE id = ? ;");
+  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
+  if (rc == SQLITE_OK) {
+    if (sqlite3_bind_int64(queryStmt, 1, id) == SQLITE_OK) {
+      rc = sqlite3_step(queryStmt);
+      if (rc == SQLITE_ROW) {
+        shared_ptr<Data> data(new Data());
+        data->wireDecode(Block(sqlite3_column_blob(queryStmt, 2),
+                              sqlite3_column_bytes(queryStmt, 2)));
+        sqlite3_finalize(queryStmt);
+        return data;
+      }
+      else if (rc == SQLITE_DONE) {
+        return shared_ptr<Data>();
+      }
+      else {
+        std::cerr << "Database query failure rc:" << rc << std::endl;
+        sqlite3_finalize(queryStmt);
+        throw Error("Database query failure");
+      }
+    }
+    else {
+      std::cerr << "select bind error" << std::endl;
+      sqlite3_finalize(queryStmt);
+      throw Error("select bind error");
+    }
+    sqlite3_finalize(queryStmt);
+  }
+  else {
+    sqlite3_finalize(queryStmt);
+    std::cerr << "select statement prepared failed" << std::endl;
+    throw Error("select statement prepared failed");
+  }
+  return shared_ptr<Data>();
+}
+
+int64_t
+SqliteStorage::size()
+{
+  sqlite3_stmt* queryStmt = 0;
+  string sql("SELECT count(*) FROM NDN_REPO ");
+  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
+  if (rc != SQLITE_OK)
+    {
+      std::cerr << "Database query failure rc:" << rc << std::endl;
+      sqlite3_finalize(queryStmt);
+      throw Error("Database query failure");
+    }
+
+  rc = sqlite3_step(queryStmt);
+  if (rc != SQLITE_ROW)
+    {
+      std::cerr << "Database query failure rc:" << rc << std::endl;
+      sqlite3_finalize(queryStmt);
+      throw Error("Database query failure");
+    }
+
+  int64_t nDatas = sqlite3_column_int64(queryStmt, 0);
+  if (m_size != nDatas) {
+    std::cerr << "The size of database is not correct! " << std::endl;
+  }
+  return nDatas;
+}
+
+} //namespace repo
diff --git a/src/storage/sqlite-storage.hpp b/src/storage/sqlite-storage.hpp
new file mode 100755
index 0000000..73579c7
--- /dev/null
+++ b/src/storage/sqlite-storage.hpp
@@ -0,0 +1,104 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014,  Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef REPO_STORAGE_SQLITE_STORAGE_HPP
+#define REPO_STORAGE_SQLITE_STORAGE_HPP
+
+#include "storage.hpp"
+#include "index.hpp"
+#include <string>
+#include <iostream>
+#include <sqlite3.h>
+#include <stdlib.h>
+#include <vector>
+#include <queue>
+#include <algorithm>
+
+namespace repo {
+
+using std::queue;
+
+class SqliteStorage : public Storage
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
+  explicit
+  SqliteStorage(const string& dbPath);
+
+  virtual
+  ~SqliteStorage();
+
+  /**
+   *  @brief  put the data into database
+   *  @param  data     the data should be inserted into databse
+   *  @return int64_t  the id number of each entry in the database
+   */
+  virtual int64_t
+  insert(const Data& data);
+
+  /**
+   *  @brief  remove the entry in the database by using id
+   *  @param  id   id number of each entry in the database
+   */
+  virtual bool
+  erase(const int64_t id);
+
+  /**
+   *  @brief  get the data from database
+   *  @para   id   id number of each entry in the database, used to find the data
+   */
+  virtual shared_ptr<Data>
+  read(const int64_t id);
+
+  /**
+   *  @brief  return the size of database
+   */
+  virtual int64_t
+  size();
+
+  /**
+   *  @brief enumerate each entry in database and call the function
+   *         insertItemToIndex to reubuild index from database
+   */
+  void
+  fullEnumerate(const ndn::function<void(const Storage::ItemMeta)>& f);
+
+private:
+  void
+  initializeRepo();
+
+private:
+  sqlite3* m_db;
+  string m_dbPath;
+  int64_t m_size;
+};
+
+
+} // namespace repo
+
+#endif // REPO_STORAGE_SQLITE_STORAGE_HPP
diff --git a/src/storage/storage-handle.hpp b/src/storage/storage-handle.hpp
deleted file mode 100644
index b75de2c..0000000
--- a/src/storage/storage-handle.hpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014,  Regents of the University of California.
- *
- * This file is part of NDN repo-ng (Next generation of NDN repository).
- * See AUTHORS.md for complete list of repo-ng authors and contributors.
- *
- * repo-ng is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef REPO_STORAGE_STORAGE_HANDLE_HPP
-#define REPO_STORAGE_STORAGE_HANDLE_HPP
-
-#include "common.hpp"
-#include "storage-method.hpp"
-
-namespace repo {
-
-/**
- * @brief this class defines handles to read, insert and delete data packets in storage media
- */
-
-class StorageHandle : noncopyable
-{
-public:
-  class Error : public std::runtime_error
-  {
-  public:
-    explicit
-    Error(const std::string& what)
-      : std::runtime_error(what)
-    {
-    }
-  };
-
-  /**
-   * @brief Create a basic class object the specified storage type
-   */
-  explicit
-  StorageHandle(StorageMethod storageMethod);
-
-  virtual
-  ~StorageHandle();
-
-  /**
-   * @return storage method defined in storage-define.hpp
-   */
-  StorageMethod
-  getStorageMethod() const;
-
-  /**
-   * @brief insert data
-   * @return true on success, false otherwise
-   */
-  virtual bool
-  insertData(const Data& data) = 0;
-
-  /**
-   * @brief delete the data that exactly matches the name
-   * @return true on success, false otherwise
-   * @note It's considered successful if Data doesn't exist.
-   */
-  virtual bool
-  deleteData(const Name& name) = 0;
-
-  /**
-  * @brief find data according to the interest. This interest may contain selectors.
-  * @param[out] data Data matching Interest.
-  * @return true if Data is found, false otherwise
-  */
-  virtual bool
-  readData(const Interest& interest, Data& data) = 0;
-
-  /**
-   * @return if storage media has data packets with this name, return true, else return false
-   */
-  virtual bool
-  hasName(const Name& name) = 0;
-
-  /**
-   * @brief select any data conforms to the selector
-   * @param[out] names Data names matching @p name and @p selectors.
-   * @return true if at least one Data is found, false otherwise
-   */
-  virtual bool
-  readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names) = 0;
-
-  /**
-   * @brief Get the number of Data packets stored
-   */
-  virtual size_t
-  size() = 0;
-
-private:
-  StorageMethod m_storageMethod;
-};
-
-inline
-StorageHandle::StorageHandle(StorageMethod storageMethod)
-  : m_storageMethod(storageMethod)
-{
-}
-
-inline
-StorageHandle::~StorageHandle()
-{
-}
-
-inline StorageMethod
-StorageHandle::getStorageMethod() const
-{
-  return m_storageMethod;
-}
-
-} // namespace repo
-
-#endif // REPO_STORAGE_STORAGE_HANDLE_HPP
diff --git a/src/storage/storage.hpp b/src/storage/storage.hpp
new file mode 100755
index 0000000..04f366f
--- /dev/null
+++ b/src/storage/storage.hpp
@@ -0,0 +1,99 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014,  Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef REPO_STORAGE_STORAGE_HPP
+#define REPO_STORAGE_STORAGE_HPP
+#include <string>
+#include <iostream>
+#include <stdlib.h>
+#include "../common.hpp"
+
+namespace repo {
+
+/**
+  * @brief Storage is a virtual abstract class which will be called by SqliteStorage
+  */
+class Storage : noncopyable
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
+public:
+  class ItemMeta
+  {
+  public:
+    int64_t id;
+    Name fullName;
+    ndn::ConstBufferPtr keyLocatorHash;
+  };
+
+public :
+
+  virtual
+  ~Storage()
+  {
+  };
+
+  /**
+   *  @brief  put the data into database
+   *  @param  data   the data should be inserted into databse
+   */
+  virtual int64_t
+  insert(const Data& data) = 0;
+
+  /**
+   *  @brief  remove the entry in the database by using id
+   *  @param  id   id number of entry in the database
+   */
+  virtual bool
+  erase(const int64_t id) = 0;
+
+  /**
+   *  @brief  get the data from database
+   *  @param  id   id number of each entry in the database, used to find the data
+   */
+  virtual shared_ptr<Data>
+  read(const int64_t id) = 0;
+
+  /**
+   *  @brief  return the size of database
+   */
+  virtual int64_t
+  size() = 0;
+
+  /**
+   *  @brief enumerate each entry in database and call the function
+   *         insertItemToIndex to reubuild index from database
+   */
+  virtual void
+  fullEnumerate(const ndn::function<void(const Storage::ItemMeta)>& f) = 0;
+
+};
+
+} // namespace repo
+
+#endif // REPO_STORAGE_Storage_HPP
