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>
impl<'conn> KvStore<'conn>
Sourcepub fn get(&self, key: &str) -> Result<Option<String>>
pub fn get(&self, key: &str) -> Result<Option<String>>
Returns the value for key, or None if the key is absent or NULL.
§Errors
Error::InvalidNameifkeyis invalid.Error::FeatureNotSupportedon gRPC transport.Error::Serverif the query fails.
Sourcepub fn set(&self, key: &str, value: &str) -> Result<()>
pub fn set(&self, key: &str, value: &str) -> Result<()>
Sets key to value, inserting or overwriting (upsert).
§Errors
Error::InvalidNameifkeyis invalid.Error::FeatureNotSupportedon gRPC transport.Error::Serverif theUPDATE/INSERTfails.
Sourcepub fn get_as<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
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
Error::InvalidNameifkeyis invalid.Error::Serializationif the stored value is not valid JSON forT.Error::FeatureNotSupported/Error::Serveras forget.
Sourcepub fn set_as<T: Serialize>(&self, key: &str, value: &T) -> Result<()>
pub fn set_as<T: Serialize>(&self, key: &str, value: &T) -> Result<()>
Serializes value to JSON and stores it under key (upsert).
§Errors
Error::InvalidNameifkeyis invalid.Error::Serializationifvaluecannot be serialized to JSON.Error::FeatureNotSupported/Error::Serveras forset.
Sourcepub fn delete(&self, key: &str) -> Result<bool>
pub fn delete(&self, key: &str) -> Result<bool>
Deletes key; returns true if a row was removed.
§Errors
Error::InvalidNameifkeyis invalid.Error::FeatureNotSupported/Error::Server.
Sourcepub fn exists(&self, key: &str) -> Result<bool>
pub fn exists(&self, key: &str) -> Result<bool>
Returns whether key is present in this store.
§Errors
Error::InvalidNameifkeyis invalid.Error::FeatureNotSupported/Error::Server.
Sourcepub fn clear(&self) -> Result<u64>
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
Sourcepub fn pop(&self) -> Result<Option<(String, String)>>
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
Sourcepub fn set_batch(&self, entries: &[(&str, &str)]) -> Result<()>
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
Error::InvalidNameif any key is invalid (checked before writing).Error::FeatureNotSupported/Error::Server.
Trait Implementations§
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> 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