remwharead  0.8.4
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 <list>
26 #include <Poco/Data/Session.h>
27 
28 namespace remwharead
29 {
30  namespace fs = std::experimental::filesystem;
31  using std::string;
32  using std::vector;
33  using std::chrono::system_clock;
34  using time_point = system_clock::time_point;
35  using std::list;
36  using Poco::Data::Session;
37 
45  class Database
46  {
47  public:
55  typedef struct entry
56  {
57  string uri;
58  string archive_uri;
59  time_point datetime;
60  vector<string> tags;
61  string title;
62  string description;
63  string fulltext;
64 
70  friend bool operator ==(const Database::entry &a,
71  const Database::entry &b);
72 
78  const string fulltext_oneline() const;
79  } entry;
80 
86  Database();
87 
93  operator bool() const;
94 
100  void store(const entry &data) const;
101 
107  const list<entry> retrieve(
108  const time_point &start = time_point(),
109  const time_point &end = system_clock::now()) const;
110 
111  private:
112  fs::path _dbpath;
113  std::unique_ptr<Session> _session;
114  bool _connected;
115  };
116 
117  using DB = Database;
118 }
119 
120 #endif // REMWHAREAD_SQLITE_HPP
struct remwharead::Database::entry entry
Describes a database entry.
const list< entry > retrieve(const time_point &start=time_point(), const time_point &end=system_clock::now()) const
Retrieve a list of Database::entry from the database.
Definition: sqlite.cpp:115
Store and retrieve files from/to SQLite.
Definition: sqlite.hpp:45
void store(const entry &data) const
Store a Database::entry in the database.
Definition: sqlite.cpp:84
Describes a database entry.
Definition: sqlite.hpp:55
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
Database()
Connects to the database and creates it if necessary.
Definition: sqlite.cpp:33