writeln!(output, "use serde::{{Serialize, Deserialize}};");
writeln!(output, "");
+ writeln!(output, "use sqlx::FromRow;");
+ writeln!(output, "");
+
+ writeln!(output, "use chrono::NaiveDate;");
+ writeln!(output, "");
+
writeln!(output, "use zakform::fields::{{TField, FOption}};");
writeln!(output, "");
writeln!(output, "let mut f = zakform::form::Form::new();");
+ let mut struct_db = String::new();
let mut struct_form = String::new();
for e in form.elements {
}
match e.dbtype.as_str() {
- "text" => { },
- "integer" => { writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::Integer);"); },
- "float" => { writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::Float);"); },
- "date" => { writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::Date);"); },
- "datetime" => { writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::DateTime);"); },
- _ => { },
+ "text" => {
+ struct_db.push_str(&format!("pub {}: String,\n", e.id));
+ },
+ "integer" => {
+ struct_db.push_str(&format!("pub {}: i32,\n", e.id));
+ writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::Integer);");
+ },
+ "float" => {
+ struct_db.push_str(&format!("pub {}: f32,\n", e.id));
+ writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::Float);");
+ },
+ "date" => {
+ struct_db.push_str(&format!("pub {}: NaiveDate,\n", e.id));
+ writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::Date);");
+ },
+ "datetime" => {
+ struct_db.push_str(&format!("pub {}: NaiveDateTime,\n", e.id));
+ writeln!(output, "fi.set_db_type(zakform::fields::FieldDbType::DateTime);");
+ },
+ _ => {
+ struct_db.push_str(&format!("pub {}: String,\n", e.id));
+ },
}
if e.max_length > 0 {
writeln!(output, "f");
writeln!(output, "}}");
+ /* db struct */
+ writeln!(output, "");
+ writeln!(output, "#[derive(Debug, Serialize, Deserialize, FormRow)]");
+ writeln!(output, "pub struct DomandaDb {{");
+ writeln!(output, "{}}}", struct_db);
+
/* form struct */
writeln!(output, "");
writeln!(output, "#[derive(Debug, Serialize, Deserialize)]");