Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
database.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
12#pragma once
13
14#include <cstddef>
15#include <filesystem>
16#include <functional>
17#include <mutex>
18#include <string_view>
19
20struct sqlite3;
21struct sqlite3_stmt;
22
23namespace entropic {
24
43public:
49 explicit SqliteDatabase(const std::filesystem::path& db_path);
50
56
57 SqliteDatabase(const SqliteDatabase&) = delete;
58 SqliteDatabase& operator=(const SqliteDatabase&) = delete;
59
65 bool initialize();
66
71 void close();
72
78 bool is_open() const;
79
87 bool execute(std::string_view sql,
88 std::function<void(sqlite3_stmt*)> binder = nullptr);
89
96 bool execute_raw(std::string_view sql);
97
106 bool fetch_one(std::string_view sql,
107 std::function<void(sqlite3_stmt*)> binder,
108 std::function<void(sqlite3_stmt*)> extractor);
109
118 size_t fetch_all(std::string_view sql,
119 std::function<void(sqlite3_stmt*)> binder,
120 std::function<void(sqlite3_stmt*)> row_handler);
121
127 sqlite3* raw_handle() const;
128
129private:
135 bool run_migrations();
136
143 sqlite3_stmt* prepare(std::string_view sql);
144
145 std::filesystem::path db_path_;
146 sqlite3* db_ = nullptr;
147 mutable std::mutex mutex_;
148};
149
150} // namespace entropic
Thread-safe SQLite database wrapper.
Definition database.h:42
bool execute(std::string_view sql, std::function< void(sqlite3_stmt *)> binder=nullptr)
Execute a write statement (INSERT, UPDATE, DELETE).
Definition database.cpp:269
bool execute_raw(std::string_view sql)
Execute raw SQL (multiple statements, no binding).
Definition database.cpp:295
bool is_open() const
Check if database is open.
Definition database.cpp:235
void close()
Close database connection.
Definition database.cpp:221
~SqliteDatabase()
Destructor — closes connection if open.
Definition database.cpp:173
sqlite3 * raw_handle() const
Get the underlying sqlite3 handle (for advanced use).
Definition database.cpp:381
size_t fetch_all(std::string_view sql, std::function< void(sqlite3_stmt *)> binder, std::function< void(sqlite3_stmt *)> row_handler)
Fetch all matching rows.
Definition database.cpp:353
bool fetch_one(std::string_view sql, std::function< void(sqlite3_stmt *)> binder, std::function< void(sqlite3_stmt *)> extractor)
Fetch a single row.
Definition database.cpp:322
bool initialize()
Initialize database and run pending migrations.
Definition database.cpp:183
Activate model on GPU (WARM → ACTIVE).