Struct quick_kv::client::default::QuickClient
source · pub struct QuickClient<T>{
pub file: Arc<Mutex<File>>,
pub cache: Arc<Mutex<HashMap<String, BinaryKv<T>>>>,
pub config: QuickConfiguration,
}Expand description
The default and recommended client to use. It is optimized for a specific schema and has multi-threading enabled by default.
It allows you to define a schema for your data, which will be used to serialize and deserialize your data. The benefit is all operations are optimized for your data type, it also makes typings easier to work with. Use this client when you want to work with data-modules that you have defined. The mini client is good for storing generic data that could change frequently.
Example
use std::path::PathBuf;
use quick_kv::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
struct User
{
name: String,
age: u8,
}
let config = QuickConfiguration::new(Some(PathBuf::from("db.qkv")), true, None);
let mut client = QuickClient::<User>::new(Some(config)).unwrap();
let user = User {
name: "John".to_string(),
age: 20,
};
client.set("user", user.clone()).unwrap();
let user_from_db = client.get("user").unwrap().unwrap();
assert_eq!(user, user_from_db);Fields§
§file: Arc<Mutex<File>>§cache: Arc<Mutex<HashMap<String, BinaryKv<T>>>>§config: QuickConfigurationImplementations§
source§impl<T> QuickClient<T>
impl<T> QuickClient<T>
pub fn new(config: Option<QuickConfiguration>) -> Result<Self>
pub fn get(&mut self, key: &str) -> Result<Option<T>>where
T: Clone,
pub fn set(&mut self, key: &str, value: T) -> Result<()>
pub fn delete(&mut self, key: &str) -> Result<()>
pub fn update(&mut self, key: &str, value: T) -> Result<()>
pub fn clear(&mut self) -> Result<()>
pub fn get_all(&mut self) -> Result<Vec<BinaryKv<T>>>
pub fn get_many(&mut self, keys: Vec<String>) -> Result<Vec<BinaryKv<T>>>
pub fn set_many(&mut self, values: Vec<BinaryKv<T>>) -> Result<()>
pub fn delete_many(&mut self, keys: Vec<String>) -> Result<()>
pub fn update_many(&mut self, values: Vec<BinaryKv<T>>) -> Result<()>
Trait Implementations§
source§impl<T> Clone for QuickClient<T>
impl<T> Clone for QuickClient<T>
source§fn clone(&self) -> QuickClient<T>
fn clone(&self) -> QuickClient<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> RefUnwindSafe for QuickClient<T>
impl<T> Send for QuickClient<T>
impl<T> Sync for QuickClient<T>
impl<T> Unpin for QuickClient<T>
impl<T> UnwindSafe for QuickClient<T>
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
Mutably borrows from an owned value. Read more