use crate::core::expr::Expr;
use crate::core::query::{DeleteQuery, SelectQuery};
use crate::core::types::Value;
pub struct ModelColumn {
pub name: &'static str,
pub column_type: &'static str,
pub nullable: bool,
pub has_default: bool,
}
pub trait Model {
const TABLE: &'static str;
const PRIMARY_KEY: &'static str;
fn columns() -> &'static [ModelColumn];
fn find() -> SelectQuery {
SelectQuery::new(Self::TABLE)
}
fn find_by_id(id: Value) -> SelectQuery {
SelectQuery::new(Self::TABLE).where_(Expr::Compare {
column: format!("\"{}\"", Self::PRIMARY_KEY),
op: "=",
value: id,
})
}
fn delete(id: Value) -> DeleteQuery {
DeleteQuery::new(Self::TABLE).where_id(id)
}
}