use crate::error::Result;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
#[async_trait]
pub trait SqlRepository<T>: Send + Sync
where
T: Send + Sync + Serialize + DeserializeOwned,
{
async fn find_by_id(&self, id: &str) -> Result<Option<T>>;
async fn find_all(&self) -> Result<Vec<T>>;
async fn find_where(&self, field: &str, value: &str) -> Result<Vec<T>>;
async fn create(&self, entity: &T) -> Result<T>;
async fn update(&self, id: &str, entity: &T) -> Result<T>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn count(&self) -> Result<u64>;
}
pub struct SqlExecutor;
impl SqlExecutor {
pub async fn query<T: DeserializeOwned>(_sql: &str) -> Result<Vec<T>> {
Ok(Vec::new())
}
pub async fn execute(_sql: &str) -> Result<u64> {
Ok(0)
}
}
pub struct Migration {
pub version: String,
pub name: String,
pub up: String,
pub down: String,
}
impl Migration {
pub fn new(version: &str, name: &str, up: &str, down: &str) -> Self {
Self {
version: version.to_string(),
name: name.to_string(),
up: up.to_string(),
down: down.to_string(),
}
}
}