Expand description
Database-driven AdminModelConfig generation.
Reads a SQLite table’s structure via PRAGMA table_info(...) and
converts each column into an AdminUiField. The result is the
same kind of AdminModelConfig the manual builder produces, so
every downstream consumer (registry, routes, persistence,
rendering) stays unaware of where the metadata came from.
Lifetime note: the registry stores &'static str for slug, table,
field names, etc. Names returned by PRAGMA are owned Strings,
so generate_from_table leaks them at registration time
(String::leak). This is a one-shot at startup — the leaks are
bounded by the number of registered models, never per-request.
§Constraints
- No CREATE TABLE generation.
ensure_table_sqlis left empty; the caller is expected to have provisioned the table already. - Identifier quoting. Table names are routed through
[
quote_ident] before being interpolated into the PRAGMA statement. SQLite pragmas do not accept bind parameters, so identifier-quoting is the safety boundary here.
Structs§
- Column
Info - A single column as reported by
PRAGMA table_info. Just the four fields the generator actually needs —dflt_valueandcidare dropped to keep the surface area minimal.
Functions§
- column_
to_ field - Decide the
AdminUiFieldshape for one column. Pure function on metadata — no DB lookup. Heuristics: - generate_
from_ table - Build an
AdminModelConfigentirely from a live table’s schema. Equivalent to hand-writing the same config — the result plugs intoregister_generatedexactly like a manual one. - generate_
model_ from_ table - Convenience pairing: introspect + box. Lets a caller stash the
result behind
Box<dyn AdminUiModel>without naming the generator type. - get_
table_ columns - Read column metadata for
tableviaPRAGMA table_info(...).