63 lines
1.3 KiB
Rust
63 lines
1.3 KiB
Rust
// BASE MODELS
|
|
use fully_pub::fully_pub;
|
|
|
|
#[derive(Debug)]
|
|
#[fully_pub]
|
|
struct Model {
|
|
module_path: Vec<String>,
|
|
name: String,
|
|
table_name: String,
|
|
fields: Vec<Field>
|
|
}
|
|
|
|
impl Model {
|
|
// pub fn concrete_fields(&self) -> Vec<Field> {
|
|
// self.fields.iter().map(|f| {
|
|
// if f.is_foreign_ref {
|
|
// Field {
|
|
// name: f.name.clone(),
|
|
// rust_type: "String".into(),
|
|
// is_nullable: f.is_nullable.clone(),
|
|
// is_unique: f.is_unique.clone(),
|
|
// is_primary: false,
|
|
// is_foreign_ref: false
|
|
// }
|
|
// } else {
|
|
// f.clone()
|
|
// }
|
|
// }).collect()
|
|
// }
|
|
}
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
#[fully_pub]
|
|
struct ForeignRefParams {
|
|
/// eg. "tokens"
|
|
reverse_relation_name: String,
|
|
/// eg. "user"
|
|
target_resource_name: String,
|
|
// /// eg. "users"
|
|
// target_resource_name_plural: String
|
|
}
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
#[fully_pub]
|
|
enum FieldForeignMode {
|
|
ForeignRef(ForeignRefParams),
|
|
NotRef
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
#[fully_pub]
|
|
struct Field {
|
|
name: String,
|
|
rust_type: String,
|
|
is_nullable: bool,
|
|
is_unique: bool,
|
|
is_primary: bool,
|
|
is_query_entrypoint: bool,
|
|
foreign_mode: FieldForeignMode
|
|
}
|
|
|