pub struct AzothDb { /* private fields */ }Expand description
Unified Axiom database
Bundles together canonical store, projection store, and projector for easy management.
Implementations§
Source§impl AzothDb
impl AzothDb
Sourcepub fn backup_with_options<P: AsRef<Path>>(
&self,
dir: P,
options: &BackupOptions,
) -> Result<()>
pub fn backup_with_options<P: AsRef<Path>>( &self, dir: P, options: &BackupOptions, ) -> Result<()>
Backup with custom options (encryption and compression)
Sourcepub fn restore_with_options<P: AsRef<Path>, Q: AsRef<Path>>(
backup_dir: P,
target_path: Q,
options: &BackupOptions,
) -> Result<Self>
pub fn restore_with_options<P: AsRef<Path>, Q: AsRef<Path>>( backup_dir: P, target_path: Q, options: &BackupOptions, ) -> Result<Self>
Restore from backup with custom options
Source§impl AzothDb
impl AzothDb
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open an Axiom database at the given path
Creates subdirectories:
{path}/canonical/- LMDB canonical store{path}/projection.db- SQLite projection store
Sourcepub fn open_with_config(
base_path: PathBuf,
canonical_config: CanonicalConfig,
projection_config: ProjectionConfig,
) -> Result<Self>
pub fn open_with_config( base_path: PathBuf, canonical_config: CanonicalConfig, projection_config: ProjectionConfig, ) -> Result<Self>
Open with custom configurations
Sourcepub fn open_with_projector_config(
base_path: PathBuf,
canonical_config: CanonicalConfig,
projection_config: ProjectionConfig,
projector_config: ProjectorConfig,
) -> Result<Self>
pub fn open_with_projector_config( base_path: PathBuf, canonical_config: CanonicalConfig, projection_config: ProjectionConfig, projector_config: ProjectorConfig, ) -> Result<Self>
Open with custom projector config
Sourcepub fn canonical(&self) -> &Arc<LmdbCanonicalStore>
pub fn canonical(&self) -> &Arc<LmdbCanonicalStore>
Get reference to canonical store
Sourcepub fn projection(&self) -> &Arc<SqliteProjectionStore>
pub fn projection(&self) -> &Arc<SqliteProjectionStore>
Get reference to projection store
Sourcepub fn projection_write_conn(&self) -> &Arc<Mutex<Connection>> ⓘ
pub fn projection_write_conn(&self) -> &Arc<Mutex<Connection>> ⓘ
Get the projection write connection.
Use this for migrations, DDL, and projector event application.
For read-only queries, prefer query() / query_async() which
automatically use the read pool for concurrent access.
§Example
let conn = db.projection_write_conn();
let guard = conn.lock();
guard.execute("INSERT INTO ...", params![])?;Sourcepub fn projection_connection(&self) -> &Arc<Mutex<Connection>> ⓘ
👎Deprecated since 0.3.0: Use query()/query_async() for reads, projection_write_conn() for writes
pub fn projection_connection(&self) -> &Arc<Mutex<Connection>> ⓘ
Get the underlying SQLite connection for the projection store.
Deprecated: prefer projection_write_conn() for writes and
query() / query_async() for reads. This method returns the
write connection, which contends with the projector.
Sourcepub fn projector(&self) -> &Projector<LmdbCanonicalStore, SqliteProjectionStore>
pub fn projector(&self) -> &Projector<LmdbCanonicalStore, SqliteProjectionStore>
Get reference to projector
Sourcepub fn event_notify(&self) -> Arc<Notify>
pub fn event_notify(&self) -> Arc<Notify>
Get the shared event notification handle.
This Notify fires after every successful event append. Consumers
(event processors, custom projectors) can call notify.notified().await
to wake immediately when new events are available, eliminating polling.
Sourcepub fn migrate(&self, manager: &MigrationManager) -> Result<()>
pub fn migrate(&self, manager: &MigrationManager) -> Result<()>
Run migrations on the projection store
Sourcepub fn backup_to<P: AsRef<Path>>(&self, dir: P) -> Result<()>
pub fn backup_to<P: AsRef<Path>>(&self, dir: P) -> Result<()>
Backup the entire database to a directory
Follows the safe backup workflow:
- Pause ingestion
- Seal canonical
- Run projector to catch up
- Backup both stores
- Resume ingestion
Sourcepub fn restore_from<P: AsRef<Path>>(
backup_dir: P,
target_path: P,
) -> Result<Self>
pub fn restore_from<P: AsRef<Path>>( backup_dir: P, target_path: P, ) -> Result<Self>
Restore from a backup directory
Sourcepub async fn query_async<F, R>(&self, f: F) -> Result<R>
pub async fn query_async<F, R>(&self, f: F) -> Result<R>
Sourcepub async fn execute_async<F>(&self, f: F) -> Result<()>
pub async fn execute_async<F>(&self, f: F) -> Result<()>
Sourcepub fn transaction<F>(&self, f: F) -> Result<()>
pub fn transaction<F>(&self, f: F) -> Result<()>
Sourcepub async fn transaction_async<F>(&self, f: F) -> Result<()>
pub async fn transaction_async<F>(&self, f: F) -> Result<()>
Execute a SQL transaction asynchronously
Sourcepub async fn submit_write<F, R>(&self, f: F) -> Result<R>
pub async fn submit_write<F, R>(&self, f: F) -> Result<R>
Execute a write operation on the canonical store asynchronously.
Opens a write transaction, passes it to the closure, and commits
atomically – all inside spawn_blocking. This replaces ad-hoc
spawn_blocking wrappers at each call site.
§Example
use azoth_core::traits::CanonicalTxn;
db.submit_write(|txn| {
txn.put_state(b"balance", b"100")?;
txn.append_event(b"{\"type\":\"deposit\",\"amount\":100}")?;
Ok(())
}).await?;Sourcepub fn write_batch(&self) -> WriteBatch<'_>
pub fn write_batch(&self) -> WriteBatch<'_>
Sourcepub fn prepare_shutdown(&self) -> Result<()>
pub fn prepare_shutdown(&self) -> Result<()>
Prepare database for shutdown
This method should be called before closing the database to ensure all pending operations complete. It:
- Pauses ingestion
- Seals the canonical store
- Runs projector to catch up
After calling this, you can create a final checkpoint using
CheckpointManager::shutdown_checkpoint(), then call close().
§Example
// Prepare for shutdown
db.prepare_shutdown()?;
// Create final checkpoint (async)
checkpoint_manager.shutdown_checkpoint().await?;
// Close database
db.close()?;