blob: 6c6006da5bd592fb3ba409cc8f0177d5e0728edb [file] [log] [blame]
Weiqi Shif0330d52014-07-09 10:54:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -04002/*
Davide Pesavento11904062022-04-14 22:33:28 -04003 * Copyright (c) 2014-2022, Regents of the University of California.
Weiqi Shif0330d52014-07-09 10:54:27 -07004 *
5 * This file is part of NDN repo-ng (Next generation of NDN repository).
6 * See AUTHORS.md for complete list of repo-ng authors and contributors.
7 *
8 * repo-ng is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef REPO_STORAGE_SQLITE_STORAGE_HPP
21#define REPO_STORAGE_SQLITE_STORAGE_HPP
22
23#include "storage.hpp"
weijia yuan3aa8d2b2018-03-06 15:35:57 -080024
weijia yuan3aa8d2b2018-03-06 15:35:57 -080025#include <sqlite3.h>
Weiqi Shif0330d52014-07-09 10:54:27 -070026
27namespace repo {
28
Weiqi Shif0330d52014-07-09 10:54:27 -070029class SqliteStorage : public Storage
30{
31public:
Weiqi Shif0330d52014-07-09 10:54:27 -070032 explicit
Wentao Shanga8f3c402014-10-30 14:03:27 -070033 SqliteStorage(const std::string& dbPath);
Weiqi Shif0330d52014-07-09 10:54:27 -070034
Davide Pesavento11904062022-04-14 22:33:28 -040035 ~SqliteStorage() override;
Weiqi Shif0330d52014-07-09 10:54:27 -070036
37 /**
38 * @brief put the data into database
39 * @param data the data should be inserted into databse
40 * @return int64_t the id number of each entry in the database
41 */
weijia yuan3aa8d2b2018-03-06 15:35:57 -080042 int64_t
43 insert(const Data& data) override;
Weiqi Shif0330d52014-07-09 10:54:27 -070044
45 /**
weijia yuan3aa8d2b2018-03-06 15:35:57 -080046 * @brief remove the entry in the database by using name as index
47 * @param name name of the data
Weiqi Shif0330d52014-07-09 10:54:27 -070048 */
weijia yuan3aa8d2b2018-03-06 15:35:57 -080049 bool
50 erase(const Name& name) override;
Weiqi Shif0330d52014-07-09 10:54:27 -070051
weijia yuan3aa8d2b2018-03-06 15:35:57 -080052 std::shared_ptr<Data>
53 read(const Name& name) override;
54
55 bool
56 has(const Name& name) override;
57
58 std::shared_ptr<Data>
59 find(const Name& name, bool exactMatch = false) override;
Weiqi Shif0330d52014-07-09 10:54:27 -070060
Alexander Afanasyev5c16cc22019-04-02 14:17:12 -040061 void
62 forEach(const std::function<void(const Name&)>& f) override;
63
Weiqi Shif0330d52014-07-09 10:54:27 -070064 /**
65 * @brief return the size of database
66 */
weijia yuan3aa8d2b2018-03-06 15:35:57 -080067 uint64_t
68 size() override;
Weiqi Shif0330d52014-07-09 10:54:27 -070069
70private:
71 void
72 initializeRepo();
73
74private:
75 sqlite3* m_db;
Wentao Shanga8f3c402014-10-30 14:03:27 -070076 std::string m_dbPath;
Weiqi Shif0330d52014-07-09 10:54:27 -070077};
78
Weiqi Shif0330d52014-07-09 10:54:27 -070079} // namespace repo
80
81#endif // REPO_STORAGE_SQLITE_STORAGE_HPP