use super::support::{enum_type, required, resolve, serial_key, with_enums};
use crate::database::introspection::{Schema, Table};
pub(super) fn table() -> Table {
Table {
name: "nodes".to_string(),
columns: vec![serial_key("id"), required("kind", "node_kind")],
primary_key: vec!["id".to_string()],
foreign_keys: Vec::new(),
uniques: Vec::new(),
indexes: Vec::new(),
view: false,
}
}
pub(super) fn schema() -> Schema {
with_enums(
vec![table()],
vec![enum_type(
"node_kind",
&["campaign_type", "campaign-type", "phone-call"],
)],
)
}
pub(super) fn keyed() -> Table {
Table {
name: "catalog".to_string(),
columns: vec![required("kind", "node_kind"), required("label", "text")],
primary_key: vec!["kind".to_string()],
foreign_keys: Vec::new(),
uniques: Vec::new(),
indexes: Vec::new(),
view: false,
}
}
pub(super) fn keyed_schema() -> Schema {
with_enums(
vec![keyed()],
vec![enum_type("node_kind", &["campaign_type", "phone-call"])],
)
}
pub(super) fn file(table: &Table, schema: &Schema, name: &str) -> String {
let model = resolve(table, schema);
crate::generators::rust::render::files(&model, schema)
.into_iter()
.find(|file| file.name == name)
.unwrap_or_else(|| panic!("{name} should be emitted"))
.contents
}
pub(super) fn shared() -> String {
super::enum_fixture::shared_for(&schema())
}