pub struct AsyncKvStore<'conn> { /* private fields */ }Expand description
A handle to one named key-value store over an AsyncConnection.
The async twin of KvStore; see it for semantics. Open
one with AsyncConnection::kv_store.
§Examples
use hyperdb_api::{AsyncConnection, CreateMode, Result};
async fn demo(conn: &AsyncConnection) -> Result<()> {
let kv = conn.kv_store("settings").await?;
kv.set("theme", "dark").await?;
assert_eq!(kv.get("theme").await?, Some("dark".to_string()));
Ok(())
}Implementations§
Source§impl<'conn> AsyncKvStore<'conn>
impl<'conn> AsyncKvStore<'conn>
Sourcepub async fn set(&self, key: &str, value: &str) -> Result<SetOutcome>
pub async fn set(&self, key: &str, value: &str) -> Result<SetOutcome>
Sets key to value, inserting or overwriting (upsert). Returns
SetOutcome indicating whether the key was newly created.
§Errors
See KvStore::set.
Sourcepub async fn set_as<T: Serialize>(
&self,
key: &str,
value: &T,
) -> Result<SetOutcome>
pub async fn set_as<T: Serialize>( &self, key: &str, value: &T, ) -> Result<SetOutcome>
Serializes value to JSON and stores it under key (upsert). Returns
SetOutcome indicating whether the key was newly created.
§Errors
See KvStore::set_as.
Sourcepub async fn set_if_absent(&self, key: &str, value: &str) -> Result<bool>
pub async fn set_if_absent(&self, key: &str, value: &str) -> Result<bool>
Inserts value under key only if key is absent.
Returns true if a row was written, false if the key already existed
(in which case nothing is written). A single INSERT ... WHERE NOT EXISTS statement decides, so there is no check-then-write race within a
connection. The backing table has no unique constraint on
(store_name, key), so two separate processes writing the same key to
a shared persistent store concurrently could both pass NOT EXISTS and
double-insert; within a single process (including the MCP daemon, which
serializes engine access) the guard is exact.
§Errors
Error::InvalidNameifkeyis invalid.Error::FeatureNotSupportedon gRPC transport.Error::Serverif theINSERTfails.
Sourcepub async fn byte_size(&self) -> Result<i64>
pub async fn byte_size(&self) -> Result<i64>
Returns the total byte size of all values in this store (0 if empty).
§Errors
See KvStore::byte_size.
Sourcepub async fn entries(&self) -> Result<Vec<(String, String)>>
pub async fn entries(&self) -> Result<Vec<(String, String)>>
Returns this store’s (key, value) pairs, sorted by key ascending.
Materializes the whole store — intended for small scratchpad stores.
§Errors
See KvStore::entries.
Sourcepub async fn clear(&self) -> Result<u64>
pub async fn clear(&self) -> Result<u64>
Deletes every key in this store; returns the number removed.
The shared backing table survives; only this store’s rows are removed.
§Errors
See KvStore::clear.
Sourcepub async fn pop(&self) -> Result<Option<(String, String)>>
pub async fn pop(&self) -> Result<Option<(String, String)>>
Removes and returns the lowest-ordered pair, or None if empty.
The peek and delete run in one transaction, so they apply atomically — either both commit, or neither does (on error the transaction is rolled back). A SQL-NULL value is returned as an empty string.
§Errors
See KvStore::pop.
Sourcepub async fn set_batch(
&self,
entries: &[(&str, &str)],
) -> Result<BatchSetOutcome>
pub async fn set_batch( &self, entries: &[(&str, &str)], ) -> Result<BatchSetOutcome>
Upserts every (key, value) pair in one transaction. Returns
BatchSetOutcome reporting how many keys were newly inserted vs.
overwritten.
All keys are validated before the transaction opens, so an invalid key aborts the whole batch without writing anything.
§Errors
See KvStore::set_batch.
Sourcepub async fn set_batch_if_absent(
&self,
entries: &[(&str, &str)],
) -> Result<BatchGuardOutcome>
pub async fn set_batch_if_absent( &self, entries: &[(&str, &str)], ) -> Result<BatchGuardOutcome>
Inserts every absent (key, value) pair in one transaction, skipping
keys that already exist. All keys are validated before the transaction
opens, so an invalid key aborts the whole batch without writing anything.
§Errors
Error::InvalidNameif any key is invalid (checked before writing).Error::FeatureNotSupported/Error::Server.
Trait Implementations§
Auto Trait Implementations§
impl<'conn> !RefUnwindSafe for AsyncKvStore<'conn>
impl<'conn> !UnwindSafe for AsyncKvStore<'conn>
impl<'conn> Freeze for AsyncKvStore<'conn>
impl<'conn> Send for AsyncKvStore<'conn>
impl<'conn> Sync for AsyncKvStore<'conn>
impl<'conn> Unpin for AsyncKvStore<'conn>
impl<'conn> UnsafeUnpin for AsyncKvStore<'conn>
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> 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