include/entropic/storage/database.h

← API

include/entropic/storage/database.h

entropic::SqliteDatabase

Thread-safe SQLite database wrapper.

entropic::SqliteDatabase::SqliteDatabase(const std::filesystem::path &db_path)

Construct with database file path.

Parameters
  • db_path — Path to SQLite file. Created if absent.
  • db_path — Path to SQLite file.

entropic::SqliteDatabase::~SqliteDatabase()

Destructor — closes connection if open.

entropic::SqliteDatabase::SqliteDatabase(const SqliteDatabase &)=delete

SqliteDatabase & entropic::SqliteDatabase::operator=(const SqliteDatabase &)=delete

bool entropic::SqliteDatabase::initialize()

Initialize database and run pending migrations.

Returns
  • true on success, false on error.
  • true on success.

void entropic::SqliteDatabase::close()

Close database connection.

bool entropic::SqliteDatabase::is_open() const

Check if database is open.

Returns
true if connection is active.

bool entropic::SqliteDatabase::execute(std::string_view sql, std::function< void(sqlite3_stmt *)> binder=nullptr)

Execute a write statement (INSERT, UPDATE, DELETE).

Execute a write statement with optional parameter binding.

Parameters
  • sql — SQL statement with ? placeholders.
  • binder — Function to bind parameters to the prepared statement.
  • binder — Function to bind parameters.
Returns
true on success.

bool entropic::SqliteDatabase::execute_raw(std::string_view sql)

Execute raw SQL (multiple statements, no binding).

Parameters
  • sql — SQL text (may contain multiple semicolon-separated statements).
  • sql — SQL text.
Returns
true on success.

bool entropic::SqliteDatabase::fetch_one(std::string_view sql, std::function< void(sqlite3_stmt *)> binder, std::function< void(sqlite3_stmt *)> extractor)

Fetch a single row.

Parameters
  • sql — SQL SELECT statement.
  • binder — Function to bind parameters.
  • extractor — Function to extract columns from result row.
Returns
true if row found.

size_t entropic::SqliteDatabase::fetch_all(std::string_view sql, std::function< void(sqlite3_stmt *)> binder, std::function< void(sqlite3_stmt *)> row_handler)

Fetch all matching rows.

Parameters
  • sql — SQL SELECT statement.
  • binder — Function to bind parameters.
  • row_handler — Called for each result row.
Returns
Number of rows fetched.

sqlite3 * entropic::SqliteDatabase::raw_handle() const

Get the underlying sqlite3 handle (for advanced use).

Get the underlying sqlite3 handle.

Returns
  • Raw sqlite3 pointer (may be nullptr if closed).
  • Raw sqlite3 pointer.