Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::SqliteDatabase Class Reference

Thread-safe SQLite database wrapper. More...

#include <entropic/storage/database.h>

Public Member Functions

 SqliteDatabase (const std::filesystem::path &db_path)
 Construct with database file path.
 
 ~SqliteDatabase ()
 Destructor — closes connection if open.
 
 SqliteDatabase (const SqliteDatabase &)=delete
 
SqliteDatabaseoperator= (const SqliteDatabase &)=delete
 
bool initialize ()
 Initialize database and run pending migrations.
 
void close ()
 Close database connection.
 
bool is_open () const
 Check if database is open.
 
bool execute (std::string_view sql, std::function< void(sqlite3_stmt *)> binder=nullptr)
 Execute a write statement (INSERT, UPDATE, DELETE).
 
bool execute_raw (std::string_view sql)
 Execute raw SQL (multiple statements, no binding).
 
bool fetch_one (std::string_view sql, std::function< void(sqlite3_stmt *)> binder, std::function< void(sqlite3_stmt *)> extractor)
 Fetch a single row.
 
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.
 
sqlite3 * raw_handle () const
 Get the underlying sqlite3 handle (for advanced use).
 

Detailed Description

Thread-safe SQLite database wrapper.

Opens a SQLite database with SQLITE_OPEN_FULLMUTEX as a safety net. Application-level std::mutex serializes all operations to prevent concurrent access patterns.

Lifecycle:
SqliteDatabase db("/path/to/entropic.db");
db.initialize(); // Creates file, runs migrations
db.execute("INSERT INTO ...", [](auto* s) { ... });
db.close(); // Or let destructor handle it
Thread-safe SQLite database wrapper.
Definition database.h:42
Version
1.8.8

Definition at line 42 of file database.h.

Constructor & Destructor Documentation

◆ SqliteDatabase()

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

Construct with database file path.

Parameters
db_pathPath to SQLite file. Created if absent.
Version
1.8.8
Parameters
db_pathPath to SQLite file.

Definition at line 165 of file database.cpp.

◆ ~SqliteDatabase()

entropic::SqliteDatabase::~SqliteDatabase ( )

Destructor — closes connection if open.

Version
1.8.8

Definition at line 173 of file database.cpp.

Member Function Documentation

◆ close()

void entropic::SqliteDatabase::close ( )

Close database connection.

Version
1.8.8

Definition at line 221 of file database.cpp.

◆ execute()

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
sqlSQL statement with ? placeholders.
binderFunction to bind parameters to the prepared statement.
Returns
true on success.
Version
1.8.8
Parameters
sqlSQL statement with ? placeholders.
binderFunction to bind parameters.
Returns
true on success.

Definition at line 269 of file database.cpp.

◆ execute_raw()

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

Execute raw SQL (multiple statements, no binding).

Parameters
sqlSQL text (may contain multiple semicolon-separated statements).
Returns
true on success.
Version
1.8.8
Parameters
sqlSQL text.
Returns
true on success.

Definition at line 295 of file database.cpp.

◆ fetch_all()

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
sqlSQL SELECT statement.
binderFunction to bind parameters.
row_handlerCalled for each result row.
Returns
Number of rows fetched.
Version
1.8.8
Parameters
sqlSQL SELECT statement.
binderFunction to bind parameters.
row_handlerCalled for each result row.
Returns
Number of rows fetched.

Definition at line 353 of file database.cpp.

◆ fetch_one()

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
sqlSQL SELECT statement.
binderFunction to bind parameters.
extractorFunction to extract columns from result row.
Returns
true if row found.
Version
1.8.8
Parameters
sqlSQL SELECT statement.
binderFunction to bind parameters.
extractorFunction to extract columns from result row.
Returns
true if row found.

Definition at line 322 of file database.cpp.

◆ initialize()

bool entropic::SqliteDatabase::initialize ( )

Initialize database and run pending migrations.

Returns
true on success, false on error.
Version
1.8.8
Returns
true on success.

Definition at line 183 of file database.cpp.

◆ is_open()

bool entropic::SqliteDatabase::is_open ( ) const

Check if database is open.

Returns
true if connection is active.
Version
1.8.8
Returns
true if connection is active.

Definition at line 235 of file database.cpp.

◆ raw_handle()

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).
Version
1.8.8
Returns
Raw sqlite3 pointer.

Definition at line 381 of file database.cpp.


The documentation for this class was generated from the following files: