#[cfg(feature = "etcd")]
pub mod etcd;
#[cfg(feature = "postgres")]
pub mod postgres;
pub mod redb;
use lightning_storage_server::model::Value;
use thiserror::Error;
use tonic::async_trait;
#[derive(Debug, Error)]
pub enum Error {
#[error("database error: {0}")]
Redb(#[from] redb::RedbError),
#[cfg(feature = "postgres")]
#[error("database error: {0}")]
Postgres(#[from] postgres::PgError),
#[cfg(feature = "etcd")]
#[error("database error: {0}")]
Etcd(#[from] etcd_client::Error),
#[error("put conflict: {0:?}")]
Conflict(Vec<(String, Option<Value>)>),
#[error("put invalid key versions: {0:?}")]
InvalidVersions(Vec<(String, Value)>),
}
#[async_trait]
pub trait Database: Send + Sync {
async fn put(&self, client_id: &[u8], kvs: &Vec<(String, Value)>) -> Result<(), Error>;
async fn get_with_prefix(
&self,
client_id: &[u8],
key_prefix: String,
) -> Result<Vec<(String, Value)>, Error>;
}