Trait bonsaidb_core::keyvalue::KeyValue
source · pub trait KeyValue: Sized + Send + Sync {
// Required method
fn execute_key_operation(&self, op: KeyOperation) -> Result<Output, Error>;
// Provided methods
fn set_key<'a, S: Into<String>, V: Serialize + Send + Sync>(
&'a self,
key: S,
value: &'a V
) -> Builder<'a, Self, V> { ... }
fn set_binary_key<'a, S: Into<String>>(
&'a self,
key: S,
bytes: &'a [u8]
) -> Builder<'a, Self, ()> { ... }
fn set_numeric_key<S: Into<String>, V: Into<Numeric>>(
&self,
key: S,
value: V
) -> Builder<'_, Self, ()> { ... }
fn increment_key_by<S: Into<String> + Send + Sync, V: Into<Numeric> + TryFrom<Numeric, Error = IncompatibleTypeError> + Send + Sync>(
&self,
key: S,
value: V
) -> Builder<'_, Self, V> { ... }
fn decrement_key_by<S: Into<String> + Send + Sync, V: Into<Numeric> + TryFrom<Numeric, Error = IncompatibleTypeError> + Send + Sync>(
&self,
key: S,
value: V
) -> Builder<'_, Self, V> { ... }
fn get_key<S: Into<String>>(&self, key: S) -> Builder<'_, Self> { ... }
fn delete_key<S: Into<String> + Send>(
&self,
key: S
) -> Result<KeyStatus, Error> { ... }
fn key_namespace(&self) -> Option<&str> { ... }
fn with_key_namespace(&self, namespace: &str) -> Namespaced<'_, Self> { ... }
}
Expand description
Key-Value store methods. The Key-Value store is designed to be a high-performance, lightweight storage mechanism.
When compared to Collections, the Key-Value store does not offer ACID-compliant transactions. Instead, the Key-Value store is made more efficient by periodically flushing the store to disk rather than during each operation. As such, the Key-Value store is intended to be used as a lightweight caching layer. However, because each of the operations it supports are executed atomically, the Key-Value store can also be utilized for synchronized locking.
Floating Point Operations
When using KeyValue::set_numeric_key()
or any numeric operations, if
a Not a Number (NaN) value is encountered, Error::NotANumber
will be returned without allowing the operation to succeed.
Positive and negative infinity values are allowed, as they do not break comparison operations.
Required Methods§
sourcefn execute_key_operation(&self, op: KeyOperation) -> Result<Output, Error>
fn execute_key_operation(&self, op: KeyOperation) -> Result<Output, Error>
Executes a single KeyOperation
.
Provided Methods§
sourcefn set_key<'a, S: Into<String>, V: Serialize + Send + Sync>(
&'a self,
key: S,
value: &'a V
) -> Builder<'a, Self, V>
fn set_key<'a, S: Into<String>, V: Serialize + Send + Sync>( &'a self, key: S, value: &'a V ) -> Builder<'a, Self, V>
Sets key
to value
. This function returns a builder that is also a
Future. Awaiting the builder will execute Command::Set
with the options
given.
sourcefn set_binary_key<'a, S: Into<String>>(
&'a self,
key: S,
bytes: &'a [u8]
) -> Builder<'a, Self, ()>
fn set_binary_key<'a, S: Into<String>>( &'a self, key: S, bytes: &'a [u8] ) -> Builder<'a, Self, ()>
Sets key
to bytes
. This function returns a builder that is also
a Future. Awaiting the builder will execute Command::Set
with
the options given.
sourcefn set_numeric_key<S: Into<String>, V: Into<Numeric>>(
&self,
key: S,
value: V
) -> Builder<'_, Self, ()>
fn set_numeric_key<S: Into<String>, V: Into<Numeric>>( &self, key: S, value: V ) -> Builder<'_, Self, ()>
Sets key
to value
. This stores the value as a Numeric
,
enabling atomic math operations to be performed on this key. This
function returns a builder that is also a Future. Awaiting the
builder will execute Command::Set
with the options given.
sourcefn increment_key_by<S: Into<String> + Send + Sync, V: Into<Numeric> + TryFrom<Numeric, Error = IncompatibleTypeError> + Send + Sync>(
&self,
key: S,
value: V
) -> Builder<'_, Self, V>
fn increment_key_by<S: Into<String> + Send + Sync, V: Into<Numeric> + TryFrom<Numeric, Error = IncompatibleTypeError> + Send + Sync>( &self, key: S, value: V ) -> Builder<'_, Self, V>
Increments key
by value
. The value stored must be a Numeric
,
otherwise an error will be returned. The result of the increment
will be the value
’s type. For example, if the stored value is
currently a u64
, but value
is a f64
, the current value will be
converted to an f64
, and the stored value will be an f64
.
sourcefn decrement_key_by<S: Into<String> + Send + Sync, V: Into<Numeric> + TryFrom<Numeric, Error = IncompatibleTypeError> + Send + Sync>(
&self,
key: S,
value: V
) -> Builder<'_, Self, V>
fn decrement_key_by<S: Into<String> + Send + Sync, V: Into<Numeric> + TryFrom<Numeric, Error = IncompatibleTypeError> + Send + Sync>( &self, key: S, value: V ) -> Builder<'_, Self, V>
Decrements key
by value
. The value stored must be a Numeric
,
otherwise an error will be returned. The result of the decrement
will be the value
’s type. For example, if the stored value is
currently a u64
, but value
is a f64
, the current value will be
converted to an f64
, and the stored value will be an f64
.
sourcefn get_key<S: Into<String>>(&self, key: S) -> Builder<'_, Self>
fn get_key<S: Into<String>>(&self, key: S) -> Builder<'_, Self>
Gets the value stored at key
. This function returns a builder that is also a
Future. Awaiting the builder will execute Command::Get
with the options
given.
sourcefn delete_key<S: Into<String> + Send>(&self, key: S) -> Result<KeyStatus, Error>
fn delete_key<S: Into<String> + Send>(&self, key: S) -> Result<KeyStatus, Error>
Deletes the value stored at key
.
sourcefn key_namespace(&self) -> Option<&str>
fn key_namespace(&self) -> Option<&str>
The current namespace.
sourcefn with_key_namespace(&self, namespace: &str) -> Namespaced<'_, Self>
fn with_key_namespace(&self, namespace: &str) -> Namespaced<'_, Self>
Access this Key-Value store within a namespace. When using the returned
Namespaced
instance, all keys specified will be separated into their
own storage designated by namespace
.