pub struct ProjectionDb;Expand description
A SQLite pool initialised from a DDL schema string.
The pool is the projection read model — event handlers write to it, API handlers read from it via plain SQL queries.
Schema versioning is handled automatically via a SHA-256 content hash.
App developers only write domain tables in their schema.sql; the
_schema bookkeeping table is owned by this library.
§In-memory
ProjectionDb::in_memory creates a fresh database on every process start
and applies the schema immediately. State is populated by replaying the
full operation log.
§On-disk
ProjectionDb::open opens (or creates) an on-disk database. On startup
it compares the hash of the supplied schema against the stored hash. If
they differ the database is wiped, the new schema applied, and the caller
is expected to replay all operations before serving traffic.
Implementations§
Source§impl ProjectionDb
impl ProjectionDb
Sourcepub async fn in_memory(schema_sql: &str) -> Result<(SqlitePool, bool), Error>
pub async fn in_memory(schema_sql: &str) -> Result<(SqlitePool, bool), Error>
Create a new in-memory SQLite pool and apply schema_sql.
The _schema table is created and populated automatically.
App developers should not include it in their schema file.
Sourcepub async fn open(
path: &str,
schema_sql: &str,
) -> Result<(SqlitePool, bool), Error>
pub async fn open( path: &str, schema_sql: &str, ) -> Result<(SqlitePool, bool), Error>
Open (or create) an on-disk SQLite database.
If the stored schema hash differs from the hash of schema_sql, all
user tables are dropped and the schema is re-applied. Returns true
if a rebuild occurred (signalling that the caller should replay ops).
Auto Trait Implementations§
impl Freeze for ProjectionDb
impl RefUnwindSafe for ProjectionDb
impl Send for ProjectionDb
impl Sync for ProjectionDb
impl Unpin for ProjectionDb
impl UnsafeUnpin for ProjectionDb
impl UnwindSafe for ProjectionDb
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request