Skip to main content

KvStore

Struct KvStore 

Source
pub struct KvStore<'conn> { /* private fields */ }
Expand description

A handle to one named key-value store, backed by KV_TABLE.

Borrows its Connection for the handle’s lifetime ('conn), matching the crate’s Catalog/Inserter borrow convention. Open one with Connection::kv_store.

§Examples

use hyperdb_api::{Connection, CreateMode, Result};

fn main() -> Result<()> {
    let conn = Connection::connect("localhost:7483", "app.hyper", CreateMode::CreateIfNotExists)?;
    let kv = conn.kv_store("settings")?;
    kv.set("theme", "dark")?;
    assert_eq!(kv.get("theme")?, Some("dark".to_string()));
    Ok(())
}

Implementations§

Source§

impl<'conn> KvStore<'conn>

Source

pub fn name(&self) -> &str

Returns this store’s validated name.

Source

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

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

§Errors
Source

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

Sets key to value, inserting or overwriting (upsert).

§Errors
Source

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

Deserializes the JSON-encoded value for key into T.

Returns None if the key is absent.

§Errors
Source

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

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

§Errors
Source

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

Deletes key; returns true if a row was removed.

§Errors
Source

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

Returns whether key is present in this store.

§Errors
Source

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

Returns the number of keys in this store.

§Errors
Source

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

Returns this store’s keys, sorted ascending.

§Errors
Source

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

pub fn pop(&self) -> Result<Option<(String, String)>>

Removes and returns the lowest-ordered key/value pair, or None if empty.

The peek and delete run in one transaction, so they apply atomically — either both the read and the delete commit, or neither does (on error the transaction is rolled back). A SQL-NULL value is returned as an empty string.

§Errors
Source

pub 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

Trait Implementations§

Source§

impl<'conn> Debug for KvStore<'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 KvStore<'conn>

§

impl<'conn> !UnwindSafe for KvStore<'conn>

§

impl<'conn> Freeze for KvStore<'conn>

§

impl<'conn> Send for KvStore<'conn>

§

impl<'conn> Sync for KvStore<'conn>

§

impl<'conn> Unpin for KvStore<'conn>

§

impl<'conn> UnsafeUnpin for KvStore<'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