Skip to main content

Module schema_introspect

Module schema_introspect 

Source
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_sql is 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§

ColumnInfo
A single column as reported by PRAGMA table_info. Just the four fields the generator actually needs — dflt_value and cid are dropped to keep the surface area minimal.

Functions§

column_to_field
Decide the AdminUiField shape for one column. Pure function on metadata — no DB lookup. Heuristics:
generate_from_table
Build an AdminModelConfig entirely from a live table’s schema. Equivalent to hand-writing the same config — the result plugs into register_generated exactly 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 table via PRAGMA table_info(...).