pub struct AsyncDejaDB { /* private fields */ }Expand description
A DejaDB that is safe to use from async code.
Cheap to clone: every clone shares one store. Operations against it serialise,
because the underlying store is &mut-driven; callers queue asynchronously
rather than occupying blocking threads. Clone this into tasks rather than
wrapping it in an Arc.
Call close when the store must be shut down before the process
moves on; otherwise dropping the last handle is enough.
Implementations§
Source§impl AsyncDejaDB
impl AsyncDejaDB
Sourcepub async fn open_with(path: &str, opts: DejaDbOptions) -> Result<Self>
pub async fn open_with(path: &str, opts: DejaDbOptions) -> Result<Self>
Open with explicit DejaDbOptions.
Sourcepub async fn open_encrypted(path: &str, key: [u8; 32]) -> Result<Self>
pub async fn open_encrypted(path: &str, key: [u8; 32]) -> Result<Self>
Open an encrypted store.
The key is held in a zeroize::Zeroizing buffer for as long as this call
owns it, so the copy handed to the blocking pool is wiped once the store is
open rather than left in freed memory.
Sourcepub async fn with<T, F>(&self, op: F) -> Result<T>
pub async fn with<T, F>(&self, op: F) -> Result<T>
Run an arbitrary operation against the store, safely, on the blocking pool.
This is the escape hatch: any DejaDB method not wrapped below stays
reachable without reintroducing the runtime hazard.
let rebuilt = db.with(|db| db.rebuild_text_index()).await?;Sourcepub async fn add_if_novel<G>(&self, grain: G) -> Result<(Hash, bool)>
pub async fn add_if_novel<G>(&self, grain: G) -> Result<(Hash, bool)>
Add a grain only if its content is not already present.
Sourcepub async fn latest(
&self,
ns: &str,
subject: &str,
relation: &str,
) -> Result<Option<DeserializedGrain>>
pub async fn latest( &self, ns: &str, subject: &str, relation: &str, ) -> Result<Option<DeserializedGrain>>
The current grain for (namespace, subject, relation).
Sourcepub async fn recall_hybrid(
&self,
ns: &str,
subject: Option<&str>,
relation: Option<&str>,
query: Option<&str>,
k: usize,
deadline: Option<Duration>,
) -> Result<Vec<DeserializedGrain>>
pub async fn recall_hybrid( &self, ns: &str, subject: Option<&str>, relation: Option<&str>, query: Option<&str>, k: usize, deadline: Option<Duration>, ) -> Result<Vec<DeserializedGrain>>
Hybrid recall (triple + text + vector legs, RRF-fused).
Sourcepub async fn recent(
&self,
ns: &str,
gtype: Option<GrainType>,
limit: usize,
) -> Result<Vec<DeserializedGrain>>
pub async fn recent( &self, ns: &str, gtype: Option<GrainType>, limit: usize, ) -> Result<Vec<DeserializedGrain>>
The most recent grains in a namespace.
Sourcepub async fn stats(&self) -> Result<StoreStats>
pub async fn stats(&self) -> Result<StoreStats>
Store statistics.
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Close the store, waiting for teardown to finish.
Dropping the last handle also closes the store, but it does so on a detached
thread and cannot be awaited: if the process exits immediately afterwards,
teardown may not have run. Call close when the store must be shut down
before the program moves on — on graceful shutdown, before copying the .db
file, or at the end of a test.
The store is shared by every clone, so this closes it for all of them: subsequent operations on any handle fail. It waits for an in-flight operation to finish first, and closing an already-closed store is a no-op.
Trait Implementations§
Source§impl Clone for AsyncDejaDB
impl Clone for AsyncDejaDB
Source§fn clone(&self) -> AsyncDejaDB
fn clone(&self) -> AsyncDejaDB
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Drop for AsyncDejaDB
impl Drop for AsyncDejaDB
Auto Trait Implementations§
impl Freeze for AsyncDejaDB
impl RefUnwindSafe for AsyncDejaDB
impl Send for AsyncDejaDB
impl Sync for AsyncDejaDB
impl Unpin for AsyncDejaDB
impl UnsafeUnpin for AsyncDejaDB
impl UnwindSafe for AsyncDejaDB
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
Source§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Fruit for 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 more