pub trait CRUDTable: Send + Sync + Serialize {
fn table_columns() -> String;
fn table_name() -> String { ... }
fn do_format_column(
driver_type: &DriverType,
column: &str,
data: &mut String
) { ... }
fn make_value_sql_arg(
&self,
db_type: &DriverType,
index: &mut usize,
skips: &[Skip<'_>]
) -> Result<(String, String, Vec<Bson>)> { ... }
fn formats(driver_type: &DriverType) -> HashMap<String, String> { ... }
fn get(&self, column: &str) -> Bson { ... }
}
Expand description
DataBase Table Model trait
if use #crud_table impl Table struct, for example: #[crud_table(table_name:“biz_activity”|table_columns:“id,name,version,delete_flag”|formats_pg:“id:{}::uuid”)]
Required Methods
fn table_columns() -> String
fn table_columns() -> String
get table fields string
for Example: “create_time,delete_flag,h5_banner_img,h5_link,id,name,pc_banner_img,pc_link,remark,sort,status,version”
you also can impl this method for static string
If a macro is used, the method is overridden by the macro
Provided Methods
fn table_name() -> String
fn table_name() -> String
get table name,default is type name for snake name
for Example: struct BizActivity{} => “biz_activity” also. you can overwrite this method return ture name
impl CRUDTable for BizActivity{ table_name() -> String{ “biz_activity”.to_string() } }
fn do_format_column(driver_type: &DriverType, column: &str, data: &mut String)
fn do_format_column(driver_type: &DriverType, column: &str, data: &mut String)
format column
return (columns_sql,columns_values_sql,args)
return cast chain column:format_str for example: HashMap<“id”,|arg|“{}::uuid”.to_string()>