RADLib
RADical C++ application framework
RADDatabase::RADSqlDatabase Class Reference

SQLite connection wrapper with RADCore event reporting. More...

#include <RADDatabase.h>

+ Inheritance diagram for RADDatabase::RADSqlDatabase:
+ Collaboration diagram for RADDatabase::RADSqlDatabase:

Public Member Functions

 RADSqlDatabase ()
 Creates a database object with no file assigned yet. More...
 
 RADSqlDatabase (std::string fileName)
 Creates a database object targeting fileName. More...
 
 ~RADSqlDatabase () override
 Closes the SQLite handle if still open. More...
 
void setFileName (std::string fileName)
 Sets the SQLite database file path used by open(). More...
 
const std::string & fileName () const
 Returns the configured SQLite database file path. More...
 
bool open ()
 Opens the configured SQLite database file. More...
 
void close ()
 Closes the SQLite connection. More...
 
bool isOpen () const
 Returns true when a SQLite connection is open. More...
 
std::string lastError () const
 Returns the most recent SQLite error message. More...
 
bool execute (const std::string &sql)
 Executes SQL that does not need row results. More...
 
RADSqlResult query (const std::string &sql)
 Executes SQL and returns collected result rows. More...
 
RADSqlStatement prepare (const std::string &sql)
 Prepares a reusable SQL statement. More...
 
RADCore::RADFutureT< RADSqlResultqueryAsync (RADCore::RADThreadPool &pool, RADCore::EventLoop &completionLoop, const std::string &sql)
 Runs query asynchronously on pool and posts completion to completionLoop. More...
 
bool beginTransaction ()
 Starts a SQLite transaction. More...
 
bool commit ()
 Commits the active transaction. More...
 
bool rollback ()
 Rolls back the active transaction. More...
 
int schemaVersion ()
 Returns current schema version from the rad_schema_version table. More...
 
bool migrateTo (int targetVersion, const std::vector< std::pair< int, std::string >> &migrations)
 Applies ordered migrations until targetVersion is reached. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void(std::string) > errorOccurred
 Raised when SQLite open, execute, query, or transaction handling fails. More...
 

Friends

class RADSqlStatement
 
class RADSqlTransaction
 

Detailed Description

SQLite connection wrapper with RADCore event reporting.

Constructor & Destructor Documentation

◆ RADSqlDatabase() [1/2]

RADDatabase::RADSqlDatabase::RADSqlDatabase ( )

Creates a database object with no file assigned yet.

◆ RADSqlDatabase() [2/2]

RADDatabase::RADSqlDatabase::RADSqlDatabase ( std::string  fileName)
explicit

Creates a database object targeting fileName.

◆ ~RADSqlDatabase()

RADDatabase::RADSqlDatabase::~RADSqlDatabase ( )
override

Closes the SQLite handle if still open.

Member Function Documentation

◆ beginTransaction()

bool RADDatabase::RADSqlDatabase::beginTransaction ( )

Starts a SQLite transaction.

◆ close()

void RADDatabase::RADSqlDatabase::close ( )

Closes the SQLite connection.

◆ commit()

bool RADDatabase::RADSqlDatabase::commit ( )

Commits the active transaction.

◆ execute()

bool RADDatabase::RADSqlDatabase::execute ( const std::string &  sql)

Executes SQL that does not need row results.

◆ fileName()

const std::string& RADDatabase::RADSqlDatabase::fileName ( ) const

Returns the configured SQLite database file path.

◆ isOpen()

bool RADDatabase::RADSqlDatabase::isOpen ( ) const

Returns true when a SQLite connection is open.

◆ lastError()

std::string RADDatabase::RADSqlDatabase::lastError ( ) const

Returns the most recent SQLite error message.

◆ migrateTo()

bool RADDatabase::RADSqlDatabase::migrateTo ( int  targetVersion,
const std::vector< std::pair< int, std::string >> &  migrations 
)

Applies ordered migrations until targetVersion is reached.

◆ open()

bool RADDatabase::RADSqlDatabase::open ( )

Opens the configured SQLite database file.

◆ prepare()

RADSqlStatement RADDatabase::RADSqlDatabase::prepare ( const std::string &  sql)

Prepares a reusable SQL statement.

◆ query()

RADSqlResult RADDatabase::RADSqlDatabase::query ( const std::string &  sql)

Executes SQL and returns collected result rows.

◆ queryAsync()

RADCore::RADFutureT<RADSqlResult> RADDatabase::RADSqlDatabase::queryAsync ( RADCore::RADThreadPool pool,
RADCore::EventLoop completionLoop,
const std::string &  sql 
)

Runs query asynchronously on pool and posts completion to completionLoop.

◆ rollback()

bool RADDatabase::RADSqlDatabase::rollback ( )

Rolls back the active transaction.

◆ schemaVersion()

int RADDatabase::RADSqlDatabase::schemaVersion ( )

Returns current schema version from the rad_schema_version table.

◆ setFileName()

void RADDatabase::RADSqlDatabase::setFileName ( std::string  fileName)

Sets the SQLite database file path used by open().

Friends And Related Function Documentation

◆ RADSqlStatement

friend class RADSqlStatement
friend

◆ RADSqlTransaction

friend class RADSqlTransaction
friend

Member Data Documentation

◆ errorOccurred

RADCore::Event<void (std::string) > RADDatabase::RADSqlDatabase::errorOccurred

Raised when SQLite open, execute, query, or transaction handling fails.


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