sqlxgentools/lib/sqlxgentools_cli/src/models.rs

64 lines
1.4 KiB
Rust
Raw Normal View History

2024-12-28 19:56:04 +01:00
// BASE MODELS
use fully_pub::fully_pub;
#[derive(Debug)]
#[fully_pub]
struct Model {
2025-01-27 09:08:04 +01:00
module_path: Vec<String>,
2024-12-28 19:56:04 +01:00
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)]
2024-12-28 19:56:04 +01:00
#[fully_pub]
struct Field {
name: String,
rust_type: String,
is_nullable: bool,
is_unique: bool,
is_primary: bool,
foreign_mode: FieldForeignMode,
// is_foreign_ref: bool,
// reverse_relation_name: Option<String>
2024-12-28 19:56:04 +01:00
}