mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-25 06:00:08 +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::sync::Arc;
|
||||||
use std::ops::Deref;
|
use rocksdb::DBVector;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CustomSettings(pub Arc<rocksdb::DB>, pub String);
|
pub struct CustomSettings(pub Arc<rocksdb::DB>, pub String);
|
||||||
|
|
||||||
impl Deref for CustomSettings {
|
impl CustomSettings {
|
||||||
type Target = rocksdb::DB;
|
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 {
|
pub fn get<K, V>(&self, key: K) -> Result<Option<DBVector>, rocksdb::Error>
|
||||||
&self.0
|
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