22 #include "tools/LogEntry_odb.h"
23 #include "tools/LogEntry_odb_pgsql.h"
24 #include "tools/LogEntry_odb_sqlite.h"
26 #include <odb/pgsql/database.hxx>
27 #include <odb/sqlite/database.hxx>
36 using Query = odb::query<Tools::LogEntry>;
37 using Result = odb::result<Tools::LogEntry>;
39 static Result fetch_sqlite(
DBPtr database,
const std::string &order_by,
40 int page_size,
int offset)
42 using SQLiteQuery = odb::sqlite::query<Tools::LogEntry>;
43 auto sl_db = std::static_pointer_cast<odb::sqlite::database>(database);
44 odb::sqlite::query<Tools::LogEntry> sl_q(
"ORDER BY" + Query::id + order_by +
45 "LIMIT" + SQLiteQuery::_val(page_size) +
46 "OFFSET" + SQLiteQuery::_val(offset));
50 static Result fetch_pgsql(
DBPtr database,
const std::string &order_by,
int page_size,
53 using PGSQLQuery = odb::pgsql::query<Tools::LogEntry>;
54 auto pg_db = std::static_pointer_cast<odb::pgsql::database>(database);
55 odb::pgsql::query<Tools::LogEntry> pg_q(
"ORDER BY" + Query::id + order_by +
56 "LIMIT" + PGSQLQuery::_val(page_size) +
57 "OFFSET" + PGSQLQuery::_val(offset));
62 int page_size,
bool order_asc)
64 std::vector<LogEntry> entries;
68 odb::transaction t(database->begin());
70 int offset = page_number * page_size;
71 std::string order_by = order_asc ?
"ASC" :
"DESC";
75 if (database->id() == odb::database_id::id_sqlite)
77 res = fetch_sqlite(database, order_by, page_size, offset);
79 else if (database->id() == odb::database_id::id_pgsql)
81 res = fetch_pgsql(database, order_by, page_size, offset);
86 entries.push_back(entry);
89 return {.entries = entries,
91 .last = view.
count / page_size,