ORE Studio 0.0.4
Loading...
Searching...
No Matches
sqlite_context.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_CONNECTIONS_REPOSITORY_SQLITE_CONTEXT_HPP
21#define ORES_CONNECTIONS_REPOSITORY_SQLITE_CONTEXT_HPP
22
23#include <filesystem>
24#include <rfl/Result.hpp>
25#include <sqlgen/Ref.hpp>
26#include <sqlgen/sqlite.hpp>
27
28namespace ores::connections::repository {
29
36class sqlite_context final {
37public:
38 using connection_type = sqlgen::sqlite::Connection;
39 using connection_ref = sqlgen::Ref<connection_type>;
40
45 explicit sqlite_context(std::filesystem::path db_path);
46
51 rfl::Result<connection_ref> connect() const;
52
56 const std::filesystem::path& db_path() const { return db_path_; }
57
61 void initialize_schema();
62
69 void purge_all_data();
70
71private:
72 std::filesystem::path db_path_;
73};
74
75}
76
77#endif
SQLite database context for connection management.
Definition sqlite_context.hpp:36
rfl::Result< connection_ref > connect() const
Get a connection to the SQLite database.
Definition sqlite_context.cpp:29
void initialize_schema()
Initialize the database schema if it doesn't exist.
Definition sqlite_context.cpp:33
void purge_all_data()
Delete all data from all tables.
Definition sqlite_context.cpp:105
const std::filesystem::path & db_path() const
Get the database file path.
Definition sqlite_context.hpp:56