mod statement;
use crate::generators::rust::model::Model;
pub fn render(model: &Model) -> String {
let supplied = model.insertable();
if supplied.is_empty() {
return empty(model);
}
statement::render(model, &supplied)
}
fn empty(model: &Model) -> String {
format!(
"use super::{name};\n\n\
impl {name} {{\n\
\t/// Inserts a row consisting entirely of database-assigned values.\n\
\tpub async fn create() -> Result<Self, sqlx::Error> {{\n\
\t\tlet sql = r#\"INSERT INTO {table} DEFAULT VALUES RETURNING *\"#;\n\n\
\t\tcrate::db_pool::fetch_one(sqlx::query_as::<_, Self>(sql)).await\n\
\t}}\n\
}}\n",
name = model.name,
table = model.table
)
}