Skip to main content

AsyncKvStore

Struct AsyncKvStore 

Source
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>

Source

pub fn name(&self) -> &str

Returns this store’s validated name.

Source

pub async fn get(&self, key: &str) -> Result<Option<String>>

Returns the value for key, or None if absent or NULL.

§Errors

See KvStore::get.

Source

pub async fn set(&self, key: &str, value: &str) -> Result<()>

Sets key to value (upsert).

§Errors

See KvStore::set.

Source

pub async fn get_as<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>

Deserializes the JSON value for key into T; None if absent.

§Errors

See KvStore::get_as.

Source

pub async fn set_as<T: Serialize>(&self, key: &str, value: &T) -> Result<()>

Serializes value to JSON and stores it under key (upsert).

§Errors

See KvStore::set_as.

Source

pub async fn delete(&self, key: &str) -> Result<bool>

Deletes key; returns true if a row was removed.

§Errors

See KvStore::delete.

Source

pub async fn exists(&self, key: &str) -> Result<bool>

Returns whether key is present.

§Errors

See KvStore::exists.

Source

pub async fn size(&self) -> Result<i64>

Returns the number of keys in this store.

§Errors

See KvStore::size.

Source

pub async fn keys(&self) -> Result<Vec<String>>

Returns this store’s keys, sorted ascending.

§Errors

See KvStore::keys.

Source

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.

Source

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.

Source

pub async fn set_batch(&self, entries: &[(&str, &str)]) -> Result<()>

Upserts every (key, value) pair in one transaction.

All keys are validated before the transaction opens, so an invalid key aborts the whole batch without writing anything.

§Errors

See KvStore::set_batch.

Trait Implementations§

Source§

impl<'conn> Debug for AsyncKvStore<'conn>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more