#[cfg(feature = "postgres")]
pub mod postgres;
pub mod sled;
use crate::model::Value;
use thiserror::Error;
use tonic::async_trait;
#[derive(Debug, Error)]
pub enum Error {
#[error("database error: {0}")]
Sled(#[from] ::sled::Error),
#[cfg(feature = "postgres")]
#[error("database error: {0}")]
Postgres(#[from] postgres::PgError),
#[error("put conflict: {0:?}")]
Conflict(Vec<(String, Option<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>;
}