Store and retrieve files from/to SQLite.
More...
#include <remwharead/sqlite.hpp>
Store and retrieve files from/to SQLite.
- Since
- 0.6.0
◆ entry
Describes a database entry.
- Since
- 0.6.0
◆ Database()
remwharead::Database::Database |
( |
| ) |
|
Connects to the database and creates it if necessary.
- Since
- 0.6.0
40 _dbpath = xdgDataHome(&xdg) / fs::path(
"remwharead");
43 if (!fs::exists(_dbpath))
45 fs::create_directories(_dbpath);
47 _dbpath /=
"database.sqlite";
49 Poco::Data::SQLite::Connector::registerConnector();
50 _session = std::make_unique<Session>(
"SQLite", _dbpath);
51 *_session <<
"CREATE TABLE IF NOT EXISTS remwharead(" 52 "uri TEXT, archive_uri TEXT, datetime TEXT, " 53 "tags TEXT, title TEXT, description TEXT, fulltext TEXT);", now;
57 catch (std::exception &e)
59 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
◆ operator bool()
remwharead::Database::operator bool |
( |
| ) |
const |
Returns true if connected to the database.
- Since
- 0.6.0
◆ retrieve()
const vector< Database::entry > remwharead::Database::retrieve |
( |
const time_point & |
start = time_point() , |
|
|
const time_point & |
end = system_clock::now() |
|
) |
| const |
Retrieve a vector of Database::entry from the database.
- Since
- 0.6.0
121 string datetime, strtags;
122 Statement select(*_session);
125 select <<
"SELECT * FROM remwharead WHERE datetime " 126 "BETWEEN ? AND ? ORDER BY datetime DESC;",
127 bind(timepoint_to_string(start,
true)),
128 bind(timepoint_to_string(end,
true)),
129 into(entrybuf.uri), into(entrybuf.archive_uri), into(datetime),
130 into(strtags), into(entrybuf.title), into(entrybuf.description),
131 into(entrybuf.fulltext), range(0, 1);
133 vector<entry> entries;
135 while(!select.done())
139 entrybuf.datetime = string_to_timepoint(datetime,
true);
143 while (pos != string::npos)
145 const size_t newpos = strtags.find(
',', pos);
146 const string tag = strtags.substr(pos, newpos - pos);
152 if (pos != string::npos)
157 entrybuf.tags = tags;
159 entries.push_back(entrybuf);
164 catch (std::exception &e)
166 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
struct remwharead::Database::entry entry
Describes a database entry.
◆ store()
void remwharead::Database::store |
( |
const entry & |
data | ) |
const |
Store a Database::entry in the database.
- Since
- 0.6.0
88 const string strdatetime = timepoint_to_string(data.datetime,
true);
90 Statement insert(*_session);
92 for (
const string &tag : data.tags)
95 if (tag != *(data.tags.rbegin()))
102 insert <<
"INSERT INTO remwharead " 103 "VALUES(?, ?, ?, ?, ?, ?, ?);",
104 useRef(data.uri), useRef(data.archive_uri),
105 useRef(strdatetime), useRef(strtags), useRef(data.title),
106 useRef(data.description), useRef(data.fulltext);
109 catch (std::exception &e)
111 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
The documentation for this class was generated from the following files: