lighthouse-pulse/beacon_node/db/src/traits.rs

29 lines
794 B
Rust
Raw Normal View History

2018-09-18 07:39:38 +00:00
pub type DBValue = Vec<u8>;
#[derive(Debug)]
pub struct DBError {
2018-10-29 19:28:50 +00:00
pub message: String,
2018-09-18 07:39:38 +00:00
}
impl DBError {
pub fn new(message: String) -> Self {
Self { message }
}
}
/// A generic database to be used by the "client' (i.e.,
/// the lighthouse blockchain client).
///
/// The purpose of having this generic trait is to allow the
/// program to use a persistent on-disk database during production,
/// but use a transient database during tests.
pub trait ClientDB: Sync + Send {
2018-10-29 19:28:50 +00:00
fn get(&self, col: &str, key: &[u8]) -> Result<Option<DBValue>, DBError>;
2018-09-18 07:39:38 +00:00
2018-10-29 19:28:50 +00:00
fn put(&self, col: &str, key: &[u8], val: &[u8]) -> Result<(), DBError>;
2018-09-20 07:36:23 +00:00
2018-10-29 19:28:50 +00:00
fn exists(&self, col: &str, key: &[u8]) -> Result<bool, DBError>;
2018-09-18 07:39:38 +00:00
2018-10-29 19:28:50 +00:00
fn delete(&self, col: &str, key: &[u8]) -> Result<(), DBError>;
}