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>
impl<Kind> DbWrite<Kind>
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
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.
Trait Implementations§
source§impl AsP2pStateWriteExt for DbWrite<DbKindP2pAgents>
impl AsP2pStateWriteExt for DbWrite<DbKindP2pAgents>
source§fn p2p_remove_agent<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 KitsuneAgent
) -> Pin<Box<dyn Future<Output = Result<bool, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DbWrite<DbKindP2pAgents>: 'async_trait,
fn p2p_remove_agent<'life0, 'life1, 'async_trait>(
&'life0 self,
agent: &'life1 KitsuneAgent
) -> Pin<Box<dyn Future<Output = Result<bool, DatabaseError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DbWrite<DbKindP2pAgents>: 'async_trait,
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> Freeze for DbWrite<Kind>where
Kind: Freeze,
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§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§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
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
source§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> ⓘ
source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§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).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.