pub struct DbWrite<Kind>(/* private fields */)
where
Kind: DbKindT;
Expand description
The canonical representation of a (singleton) database. The wrapper contains methods for managing transactions and database connections,
Implementations§
source§impl<Kind> DbWrite<Kind>where
Kind: DbKindT + Send + Sync + 'static,
impl<Kind> DbWrite<Kind>where Kind: DbKindT + Send + Sync + 'static,
sourcepub fn open(
path_prefix: &Path,
kind: Kind
) -> Result<DbWrite<Kind>, DatabaseError>
pub fn open( path_prefix: &Path, kind: Kind ) -> Result<DbWrite<Kind>, DatabaseError>
Create or open an existing database reference,
pub fn open_with_sync_level( path_prefix: &Path, kind: Kind, sync_level: DbSyncLevel ) -> Result<DbWrite<Kind>, DatabaseError>
pub fn new( path_prefix: Option<&Path>, kind: Kind, sync_level: DbSyncLevel, statement_trace_fn: Option<fn(_: &str)> ) -> Result<DbWrite<Kind>, DatabaseError>
pub async fn write_async<E, R, F>(&self, f: F) -> Result<R, E>where E: From<DatabaseError> + Send + 'static, F: FnOnce(&mut Transaction<'_>) -> Result<R, E> + Send + 'static, R: Send + 'static,
pub fn available_writer_count(&self) -> usize
pub fn available_reader_count(&self) -> usize
sourcepub fn test(path: &Path, kind: Kind) -> Result<DbWrite<Kind>, DatabaseError>
pub fn test(path: &Path, kind: Kind) -> Result<DbWrite<Kind>, DatabaseError>
Create a unique db in a temp dir with no static management of the connection pool, useful for testing.
pub fn test_in_mem(kind: Kind) -> Result<DbWrite<Kind>, DatabaseError>
pub fn test_write<R, F>(&self, f: F) -> Rwhere F: FnOnce(&mut Transaction<'_>) -> R + Send + 'static, R: Send + 'static,
Methods from Deref<Target = DbRead<Kind>>§
sourcepub async fn read_async<E, R, F>(&self, f: F) -> Result<R, E>where
E: From<DatabaseError> + Send + 'static,
F: FnOnce(Transaction<'_>) -> Result<R, E> + Send + 'static,
R: Send + 'static,
pub async fn read_async<E, R, F>(&self, f: F) -> Result<R, E>where E: From<DatabaseError> + Send + 'static, F: FnOnce(Transaction<'_>) -> Result<R, E> + Send + 'static, R: Send + 'static,
Execute a read closure on the database by acquiring a connection from the pool, starting a new transaction and running the closure with that transaction.
Note that it is not enforced that your closure runs read-only operations or that it finishes quickly so it is up to the caller to use this function as intended.
sourcepub async fn get_read_txn(&self) -> Result<PTxnGuard, DatabaseError>
pub async fn get_read_txn(&self) -> Result<PTxnGuard, DatabaseError>
Intended to be used for transactions that need to be kept open for a longer period of time than just running a
sequence of reads using read_async
. You should default to read_async
and only call this if you have a good
reason.
A valid reason for this is holding read transactions across multiple databases as part of a cascade query.
pub fn test_read<R, F>(&self, f: F) -> Rwhere F: FnOnce(Transaction<'_>) -> R + Send + 'static, R: Send + 'static,
Trait Implementations§
source§impl<Kind> ReadAccess<Kind> for DbWrite<Kind>where
Kind: DbKindT,
impl<Kind> ReadAccess<Kind> for DbWrite<Kind>where Kind: DbKindT,
source§fn read_async<'life0, 'async_trait, E, R, F>(
&'life0 self,
f: F
) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'async_trait>>where
'life0: 'async_trait,
E: From<DatabaseError> + Send + 'static + 'async_trait,
F: FnOnce(Transaction<'_>) -> Result<R, E> + Send + 'static + 'async_trait,
R: Send + 'static + 'async_trait,
DbWrite<Kind>: 'async_trait,
fn read_async<'life0, 'async_trait, E, R, F>( &'life0 self, f: F ) -> Pin<Box<dyn Future<Output = Result<R, E>> + Send + 'async_trait>>where 'life0: 'async_trait, E: From<DatabaseError> + Send + 'static + 'async_trait, F: FnOnce(Transaction<'_>) -> Result<R, E> + Send + 'static + 'async_trait, R: Send + 'static + 'async_trait, DbWrite<Kind>: 'async_trait,
Auto Trait Implementations§
impl<Kind> !RefUnwindSafe for DbWrite<Kind>
impl<Kind> Send for DbWrite<Kind>
impl<Kind> Sync for DbWrite<Kind>
impl<Kind> Unpin for DbWrite<Kind>where Kind: Unpin,
impl<Kind> !UnwindSafe for DbWrite<Kind>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
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
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> 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> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.