mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
feat: Allow to retrieve config from Database and DatabaseView
This commit is contained in:
parent
37578ed74f
commit
d5119db165
@ -279,13 +279,17 @@ impl DatabaseIndex {
|
||||
self.view.load()
|
||||
}
|
||||
|
||||
fn get_config(&self) -> Config {
|
||||
self.view().config().clone()
|
||||
}
|
||||
|
||||
fn update_config(&self, config: Config) -> Result<Arc<DatabaseView<Arc<DB>>>, Box<Error>>{
|
||||
let data = bincode::serialize(&config)?;
|
||||
self.db.put(CONFIG, &data)?;
|
||||
|
||||
let snapshot = Snapshot::new(self.db.clone());
|
||||
let view = Arc::new(DatabaseView::new(snapshot)?);
|
||||
self.view.set(view.clone());
|
||||
self.view.store(view.clone());
|
||||
|
||||
Ok(view)
|
||||
}
|
||||
@ -393,6 +397,12 @@ impl Database {
|
||||
Ok(index_guard.val().view())
|
||||
}
|
||||
|
||||
pub fn get_config(&self, index: &str) -> Result<Config, Box<Error>> {
|
||||
let index_guard = self.indexes.get(index).ok_or("Index not found")?;
|
||||
|
||||
Ok(index_guard.val().get_config())
|
||||
}
|
||||
|
||||
pub fn update_config(&self, index: &str, config: Config) -> Result<Arc<DatabaseView<Arc<DB>>>, Box<Error>>{
|
||||
let index_guard = self.indexes.get(index).ok_or("Index not found")?;
|
||||
|
||||
|
@ -58,6 +58,10 @@ where D: Deref<Target=DB>
|
||||
&self.snapshot
|
||||
}
|
||||
|
||||
pub fn config(&self) -> &Config {
|
||||
&self.config
|
||||
}
|
||||
|
||||
pub fn get(&self, key: &[u8]) -> Result<Option<DBVector>, Box<Error>> {
|
||||
Ok(self.snapshot.get(key)?)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user