mod statement;
use crate::database::introspection::Schema;
use crate::generators::rust::model::Model;
pub fn render(model: &Model, schema: &Schema) -> String {
let Some(key) = model.key() else {
return unsupported(
model,
"a single-column primary key is needed to address the row to update",
);
};
let writable = model.updatable();
if writable.is_empty() {
return unsupported(model, "every column is either the key or database-assigned");
}
statement::render(model, key, &writable, schema)
}
fn unsupported(model: &Model, reason: &str) -> String {
format!(
"//! No update was generated for `{}`: {reason}.\n\
//!\n\
//! Add one here if the table needs it; this file is regenerated, so prefer\n\
//! a sibling module for code you intend to keep.\n",
model.table
)
}