pub struct SqliteProjectionStore { /* private fields */ }Expand description
SQLite-backed projection store
Implementations§
Source§impl SqliteProjectionStore
impl SqliteProjectionStore
Sourcepub fn conn(&self) -> &Arc<Mutex<Connection>>
pub fn conn(&self) -> &Arc<Mutex<Connection>>
Get the underlying connection (for migrations and custom queries)
Returns an Arc to the Mutex-protected SQLite connection. Users should lock the mutex to access the connection.
Sourcepub async fn query_async<F, R>(&self, f: F) -> Result<R>
pub async fn query_async<F, R>(&self, f: F) -> Result<R>
Execute a read-only SQL query asynchronously
This method runs the query on a separate thread to avoid blocking, making it safe to call from async contexts.
§Example
ⓘ
let balance: i64 = store.query_async(|conn| {
conn.query_row("SELECT balance FROM accounts WHERE id = ?1", [account_id], |row| row.get(0))
}).await?;Sourcepub async fn execute_async<F>(&self, f: F) -> Result<()>
pub async fn execute_async<F>(&self, f: F) -> Result<()>
Execute arbitrary SQL statements (DDL/DML) asynchronously
Useful for creating tables, indexes, or performing bulk updates.
§Example
ⓘ
store.execute_async(|conn| {
conn.execute("CREATE TABLE IF NOT EXISTS balances (id INTEGER PRIMARY KEY, amount INTEGER)", [])?;
conn.execute("CREATE INDEX IF NOT EXISTS idx_amount ON balances(amount)", [])?;
Ok(())
}).await?;Sourcepub fn transaction<F>(&self, f: F) -> Result<()>
pub fn transaction<F>(&self, f: F) -> Result<()>
Execute a transaction with multiple SQL statements
The closure receives a transaction object and can execute multiple statements atomically. If the closure returns an error, the transaction is rolled back.
§Example
ⓘ
store.transaction(|tx| {
tx.execute("INSERT INTO accounts (id, balance) VALUES (?1, ?2)", params![1, 100])?;
tx.execute("INSERT INTO accounts (id, balance) VALUES (?1, ?2)", params![2, 200])?;
Ok(())
})?;Sourcepub async fn transaction_async<F>(&self, f: F) -> Result<()>
pub async fn transaction_async<F>(&self, f: F) -> Result<()>
Execute a transaction asynchronously
Trait Implementations§
Source§impl ProjectionStore for SqliteProjectionStore
impl ProjectionStore for SqliteProjectionStore
type Txn<'a> = SimpleProjectionTxn<'a>
Source§fn open(cfg: ProjectionConfig) -> Result<Self>
fn open(cfg: ProjectionConfig) -> Result<Self>
Open a projection store
Source§fn get_cursor(&self) -> Result<EventId>
fn get_cursor(&self) -> Result<EventId>
Get the current cursor (last applied event ID)
Source§fn restore_from(path: &Path, cfg: ProjectionConfig) -> Result<Self>
fn restore_from(path: &Path, cfg: ProjectionConfig) -> Result<Self>
Restore from a backup
Source§fn schema_version(&self) -> Result<u32>
fn schema_version(&self) -> Result<u32>
Get the schema version
Auto Trait Implementations§
impl Freeze for SqliteProjectionStore
impl RefUnwindSafe for SqliteProjectionStore
impl Send for SqliteProjectionStore
impl Sync for SqliteProjectionStore
impl Unpin for SqliteProjectionStore
impl UnwindSafe for SqliteProjectionStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more