remwharead  0.6.3
sqlite.hpp
1 /* This file is part of remwharead.
2  * Copyright © 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef REMWHAREAD_SQLITE_HPP
18 #define REMWHAREAD_SQLITE_HPP
19 
20 #include <experimental/filesystem>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include <chrono>
25 #include <Poco/Data/Session.h>
26 
27 namespace remwharead
28 {
29  namespace fs = std::experimental::filesystem;
30  using std::string;
31  using std::vector;
32  using std::chrono::system_clock;
33  using time_point = system_clock::time_point;
34  using Poco::Data::Session;
35 
43  class Database
44  {
45  public:
53  typedef struct entry
54  {
55  string uri;
56  string archive_uri;
57  time_point datetime;
58  vector<string> tags;
59  string title;
60  string description;
61  string fulltext;
62 
68  friend bool operator ==(const Database::entry &a,
69  const Database::entry &b);
70 
76  const string fulltext_oneline() const;
77  } entry;
78 
84  Database();
85 
91  operator bool() const;
92 
98  void store(const entry &data) const;
99 
105  const vector<entry> retrieve(
106  const time_point &start = time_point(),
107  const time_point &end = system_clock::now()) const;
108 
109  private:
110  fs::path _dbpath;
111  std::unique_ptr<Session> _session;
112  bool _connected;
113  };
114 
115  using DB = Database;
116 }
117 
118 #endif // REMWHAREAD_SQLITE_HPP
struct remwharead::Database::entry entry
Describes a database entry.
Store and retrieve files from/to SQLite.
Definition: sqlite.hpp:43
void store(const entry &data) const
Store a Database::entry in the database.
Definition: sqlite.cpp:84
Describes a database entry.
Definition: sqlite.hpp:53
Definition: bookmarks.cpp:22
friend bool operator==(const Database::entry &a, const Database::entry &b)
Returns true if date and time are equal.
Definition: sqlite.cpp:68
const string fulltext_oneline() const
The full text in one line.
Definition: sqlite.cpp:73
const vector< entry > retrieve(const time_point &start=time_point(), const time_point &end=system_clock::now()) const
Retrieve a vector of Database::entry from the database.
Definition: sqlite.cpp:115
Database()
Connects to the database and creates it if necessary.
Definition: sqlite.cpp:33