Store and retrieve files from/to SQLite.
More...
#include <remwharead/sqlite.hpp>
|
static string | tags_to_string (const vector< string > &tags) |
| Returns tags as comma separated string. More...
|
|
Store and retrieve files from/to SQLite.
- Since
- 0.6.0
◆ Database()
remwharead::Database::Database |
( |
| ) |
|
Connects to the database and creates it if necessary.
- Since
- 0.6.0
40 _dbpath = get_data_home();
41 if (!fs::exists(_dbpath))
43 fs::create_directories(_dbpath);
45 _dbpath /=
"database.sqlite";
47 Poco::Data::SQLite::Connector::registerConnector();
48 _session = std::make_unique<Session>(
"SQLite", _dbpath);
49 *_session <<
"CREATE TABLE IF NOT EXISTS remwharead(" 50 "uri TEXT, archive_uri TEXT, datetime TEXT, " 51 "tags TEXT, title TEXT, description TEXT, fulltext TEXT);", now;
55 catch (std::exception &e)
57 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
◆ operator bool()
remwharead::Database::operator bool |
( |
| ) |
const |
|
explicit |
Returns true if connected to the database.
- Since
- 0.6.0
◆ remove()
size_t remwharead::Database::remove |
( |
const string & |
uri | ) |
|
Remove all entries with this URI from database.
- Returns
- Number of removed entries.
- Since
- 0.9.0
162 Statement del(*_session);
164 del <<
"DELETE FROM remwharead WHERE uri = ?;", bind(uri);
166 return del.execute();
◆ retrieve()
list< Database::entry > remwharead::Database::retrieve |
( |
const time_point & |
start = time_point() , |
|
|
const time_point & |
end = system_clock::now() |
|
) |
| const |
Retrieve a list of Database::entry from the database.
- Since
- 0.6.0
109 Database::entry entrybuf;
112 Statement select(*_session);
115 select <<
"SELECT * FROM remwharead WHERE datetime " 116 "BETWEEN ? AND ? ORDER BY datetime DESC;",
117 bind(timepoint_to_string(start,
true)),
118 bind(timepoint_to_string(end,
true)),
119 into(entrybuf.uri), into(entrybuf.archive_uri), into(datetime),
120 into(strtags), into(entrybuf.title), into(entrybuf.description),
121 into(entrybuf.fulltext), range(0, 1);
125 while(!select.done() && select.execute() != 0)
127 entrybuf.datetime = string_to_timepoint(datetime,
true);
131 while (pos != string::npos)
133 const size_t newpos = strtags.find(
',', pos);
134 const string tag = strtags.substr(pos, newpos - pos);
140 if (pos != string::npos)
145 entrybuf.tags = tags;
147 entries.push_back(entrybuf);
152 catch (std::exception &e)
154 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
◆ store()
void remwharead::Database::store |
( |
const entry & |
data | ) |
const |
Store a Database::entry in the database.
- Since
- 0.6.0
86 const string strdatetime = timepoint_to_string(data.datetime,
true);
88 Statement insert(*_session);
91 insert <<
"INSERT INTO remwharead " 92 "VALUES(?, ?, ?, ?, ?, ?, ?);",
93 useRef(data.uri), useRef(data.archive_uri),
94 useRef(strdatetime), useRef(strtags), useRef(data.title),
95 useRef(data.description), useRef(data.fulltext);
98 catch (std::exception &e)
100 cerr <<
"Error in " << __func__ <<
": " << e.what() << endl;
static string tags_to_string(const vector< string > &tags)
Returns tags as comma separated string.
Definition: sqlite.cpp:169
◆ tags_to_string()
string remwharead::Database::tags_to_string |
( |
const vector< string > & |
tags | ) |
|
|
static |
Returns tags as comma separated string.
- Since
- 0.9.0
173 for (
const string &tag : tags)
176 if (tag != *(tags.rbegin()))
The documentation for this class was generated from the following files: