use async_trait::async_trait;
use thiserror::Error;
#[async_trait]
pub trait DatabasePool {
async fn initiate(&self, table_name: &str) -> Result<(), DatabaseError>;
async fn count(&self, table_name: &str) -> Result<i64, DatabaseError>;
async fn store(
&self,
id: &str,
session: &str,
expires: i64,
table_name: &str,
) -> Result<(), DatabaseError>;
async fn load(&self, id: &str, table_name: &str) -> Result<Option<String>, DatabaseError>;
async fn delete_one_by_id(&self, id: &str, table_name: &str) -> Result<(), DatabaseError>;
async fn exists(&self, id: &str, table_name: &str) -> Result<bool, DatabaseError>;
async fn delete_by_expiry(&self, table_name: &str) -> Result<Vec<String>, DatabaseError>;
async fn delete_all(&self, table_name: &str) -> Result<(), DatabaseError>;
async fn get_ids(&self, table_name: &str) -> Result<Vec<String>, DatabaseError>;
fn auto_handles_expiry(&self) -> bool;
}
#[derive(Error, Debug)]
pub enum DatabaseError {
#[error("Database insert error {0}")]
GenericAcquire(String),
#[error("Database insert error {0}")]
GenericInsertError(String),
#[error("Database select error {0}")]
GenericSelectError(String),
#[error("Database create error {0}")]
GenericCreateError(String),
#[error("Database delete error {0}")]
GenericDeleteError(String),
#[error("{0}")]
GenericNotSupportedError(String),
}