mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-25 04:57:17 +00:00
Add ClientDB exists()
method
This commit is contained in:
parent
f64b8e30a1
commit
f6330ce967
@ -107,6 +107,21 @@ impl ClientDB for DiskDB {
|
||||
Some(handle) => self.db.put_cf(handle, key, val).map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true if some key exists in some column.
|
||||
fn exists(&self, col: &str, key: &[u8])
|
||||
-> Result<bool, DBError>
|
||||
{
|
||||
/*
|
||||
* I'm not sure if this is the correct way to read if some
|
||||
* block exists. Naievely I would expect this to unncessarily
|
||||
* copy some data, but I could be wrong.
|
||||
*/
|
||||
match self.db.cf_handle(col) {
|
||||
None => Err(DBError{ message: "Unknown column".to_string() }),
|
||||
Some(handle) => Ok(self.db.get_cf(handle, key)?.is_some())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,5 +26,8 @@ pub trait ClientDB: Sync + Send {
|
||||
|
||||
fn put(&self, col: &str, key: &[u8], val: &[u8])
|
||||
-> Result<(), DBError>;
|
||||
|
||||
fn exists(&self, col: &str, key: &[u8])
|
||||
-> Result<bool, DBError>;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user