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 <sqlite/connection.hpp>
26 #include "types.hpp"
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 
36  class Database
37  {
38  public:
39  typedef struct entry
40  {
41  string uri;
42  string archive_uri;
43  time_point datetime;
44  vector<string> tags;
45  string title;
46  string description;
47  string fulltext;
48 
50  friend bool operator ==(const Database::entry &a,
51  const Database::entry &b);
53  const string fulltext_oneline() const;
54  } entry;
55 
56  Database();
57  operator bool() const;
58 
60  void store(const entry &data) const;
61 
63  const vector<entry> retrieve(
64  const time_point &start = time_point(),
65  const time_point &end = system_clock::now()) const;
66 
67  private:
68  fs::path _dbpath;
69  std::unique_ptr<sqlite::connection> _con;
70  bool _connected;
71  };
72 
73  using DB = Database;
74 }
75 
76 #endif // REMWHAREAD_SQLITE_HPP
Definition: sqlite.hpp:36
void store(const entry &data) const
Store in database.
Definition: sqlite.cpp:87
Definition: sqlite.hpp:39
Definition: search.cpp:23
friend bool operator==(const Database::entry &a, const Database::entry &b)
Returns true if date & time are equal.
Definition: sqlite.cpp:66
const string fulltext_oneline() const
The full text in one line.
Definition: sqlite.cpp:76
const vector< entry > retrieve(const time_point &start=time_point(), const time_point &end=system_clock::now()) const
retrieve from database.
Definition: sqlite.cpp:114