mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 21:20:24 +01:00
feat: Implement some convenient accessors for custom settings
This commit is contained in:
parent
ce61c16dbe
commit
6f258f71d5
@ -1,13 +1,22 @@
|
||||
use std::sync::Arc;
|
||||
use std::ops::Deref;
|
||||
use rocksdb::DBVector;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CustomSettings(pub Arc<rocksdb::DB>, pub String);
|
||||
|
||||
impl Deref for CustomSettings {
|
||||
type Target = rocksdb::DB;
|
||||
impl CustomSettings {
|
||||
pub fn set<K, V>(&self, key: K, value: V) -> Result<(), rocksdb::Error>
|
||||
where K: AsRef<[u8]>,
|
||||
V: AsRef<[u8]>,
|
||||
{
|
||||
let cf = self.0.cf_handle(&self.1).unwrap();
|
||||
self.0.put_cf(cf, key, value)
|
||||
}
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
pub fn get<K, V>(&self, key: K) -> Result<Option<DBVector>, rocksdb::Error>
|
||||
where K: AsRef<[u8]>,
|
||||
{
|
||||
let cf = self.0.cf_handle(&self.1).unwrap();
|
||||
self.0.get_cf(cf, key)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user