pub mod hooks;
#[cfg(test)]
mod tests;
pub trait TableInfo {
fn identifier() -> &'static [&'static str];
}
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Column {
name: String,
rust_type: String,
nullable: bool,
}
impl Column {
pub fn new(name: impl Into<String>, rust_type: impl Into<String>, nullable: bool) -> Self {
let rust_type = rust_type.into();
let rust_type: String = rust_type.chars().filter(|c| !c.is_whitespace()).collect();
Self {
name: name.into(),
rust_type,
nullable,
}
}
pub fn name(&self) -> &str {
self.name.as_str()
}
pub fn nullable(&self) -> bool {
self.nullable
}
pub fn rust_type(&self) -> &str {
self.rust_type.as_str()
}
}
pub trait TableColumns {
type ColumnStruct: TableColumns + Default;
fn primary_keys() -> Vec<Column>;
fn select_columns() -> Vec<Column>;
fn update_columns() -> Vec<Column>;
fn insert_columns() -> Vec<Column>;
}
pub trait UniqueIdentifier {
fn id_column() -> Column;
}
use crate::errors::Result;
use crate::query::clause::ParamArgs;
pub trait WriteToArgs {
fn bind<'s, 'c, 'a, 'p>(&'s self, column: &'c str, args: &'a mut ParamArgs<'p>) -> Result<()>
where
's: 'p;
}
pub trait ColumnDefaultCheck {
fn col_is_default(&self, column: &str) -> Result<bool>;
}
pub trait UpdateFromRow {
fn update_from_row(&mut self, row: &mut crate::Row) -> crate::errors::Result<()>;
}
pub trait HasSchema: Sync + Send {
type Schema: Default + TableInfo;
}
pub trait PrimaryKeyValue {
type PrimaryKeyType;
fn primary_key_value(&self) -> Self::PrimaryKeyType;
}
pub trait ForeignKeyPartialEq<Rhs> {
fn eq(&self, foreign_key_column: &str, other: &Rhs) -> bool;
}
mod tableident;
pub use tableident::TableIdent;