weldscli_lib/config/
column.rs1use serde::{Deserialize, Serialize};
2use welds::detect::ColumnDef;
3
4#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
5pub struct Column {
6 pub db_name: String,
7 pub db_type: String,
8 pub model_name: String,
9 #[serde(default)]
10 pub is_null: bool,
11 #[serde(default)]
12 pub primary_key: bool,
13 #[serde(default)]
14 pub writeable: bool,
15}
16
17impl Column {
18 pub fn new(def: &ColumnDef) -> Self {
19 use inflector::Inflector;
20 Column {
21 db_name: def.name().to_owned(),
22 db_type: def.ty().to_owned(),
23 model_name: def.name().to_snake_case(),
24 is_null: def.null(),
25 primary_key: def.primary_key(),
26 writeable: def.updatable(),
27 }
28 }
29
30 pub fn update_from(&mut self, def: &ColumnDef) {
31 self.db_name = def.name().to_owned();
32 self.db_type = def.ty().to_owned();
33 self.is_null = def.null();
34 self.primary_key = def.primary_key();
35 self.writeable = def.updatable();
36 }
37}