mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08: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…
Reference in New Issue
Block a user