pub mod clickhouse;
pub mod mysql;
pub mod postgres;
pub mod sqlite;
use crate::template::kit::Kit;
use crate::template::render::Render;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Table2Comment {
pub table_name: String,
pub table_comment: Option<String>,
}
#[derive(Serialize, Clone, Default, Debug)]
pub struct Table {
pub table_name: String,
pub struct_name: String,
pub fields: Vec<Field>,
pub comment: String,
pub index_key: Vec<Vec<String>>,
pub unique_key: Vec<Vec<String>>,
}
impl Render for Table {}
#[allow(non_snake_case)]
#[derive(Serialize, Clone, Default, Debug)]
pub struct Field {
pub field_name: String,
pub FieldName: String,
pub fieldName: String,
pub database_field_type: String,
pub field_type: String,
pub comment: String,
pub is_null: u8,
pub default: Option<String>,
}
impl Table {
pub async fn skip_fields(&self, skip_fields: Vec<String>) -> Table {
let mut fields = vec![];
for field in self.fields.iter() {
let mut flag = true;
for keys in &self.index_key {
if keys.contains(&field.field_name) {
fields.push(field.to_owned());
flag = false;
continue;
}
}
if !skip_fields.contains(&field.field_name) && flag {
fields.push(field.to_owned());
}
}
Table {
table_name: self.table_name.to_owned(),
struct_name: self.struct_name.to_owned(),
fields,
comment: self.comment.to_owned(),
index_key: self.index_key.to_owned(),
unique_key: self.unique_key.to_owned(),
}
}
pub async fn contain_fields(&self, contain_fields: Vec<String>) -> Table {
let mut fields = vec![];
for field in self.fields.iter() {
let mut flag = true;
for keys in &self.index_key {
if keys.contains(&field.field_name) {
fields.push(field.to_owned());
flag = false;
continue;
}
}
if contain_fields.contains(&field.field_name) && flag {
fields.push(field.to_owned());
}
}
Table {
table_name: self.table_name.to_owned(),
struct_name: self.struct_name.to_owned(),
fields,
comment: self.comment.to_owned(),
index_key: self.index_key.to_owned(),
unique_key: self.unique_key.to_owned(),
}
}
}
impl Kit for Field {}