feat: Allow to retrieve config from Database and DatabaseView

This commit is contained in:
Quentin de Quelen 2019-02-12 18:41:51 +01:00
parent 37578ed74f
commit d5119db165
2 changed files with 15 additions and 1 deletions

View File

@ -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")?;

View File

@ -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)?)
}