use crate::ValType;
pub(crate) fn map_type(name: &str) -> Option<ValType> {
Some(match name {
"int" | "integer" | "bigint" | "serial" | "bigserial" => ValType::I64,
"real" | "float" | "double precision" | "numeric" | "decimal" => ValType::F64,
"text" | "varchar" | "char" | "uuid" | "timestamp" | "timestamptz" | "date" | "bool"
| "boolean" | "json" | "jsonb" => ValType::Str,
_ => return None,
})
}
pub(crate) fn takes_args(name: &str) -> bool {
matches!(name, "varchar" | "char" | "numeric" | "decimal" | "float")
}
pub(crate) fn mapping_note(table: &str, column: &str, sql_ty: &str) -> Option<String> {
let tail = match sql_ty {
"serial" | "bigserial" => {
"i64, but ids do NOT auto-increment — allocate them app-side (INCR block, cookbook \u{a7}3)"
}
"numeric" | "decimal" => {
"f64 — fixed-point precision becomes binary float; keep money as integer cents if exactness matters"
}
"timestamp" | "timestamptz" | "date" => {
"str — kevy stores app-encoded time; use a fixed-width sortable encoding (RFC3339 or zero-padded epoch) so ranges order correctly"
}
"json" | "jsonb" => {
"str — flatten the paths you index into their own columns (cookbook \u{a7}9); JSON-path queries are permanently out"
}
"bool" | "boolean" => "str — store '0'/'1'",
"uuid" => "str — stored as its text form",
_ => return None,
};
Some(format!("{table}.{column}: {sql_ty} \u{2192} {tail}"))
}