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