Expand description
fse-schema — the shared schema layer of the fse ORM.
One schema model with three consumers:
fse-orm-macrosparses a single#[derive(Table)]struct into aTableDefto generate compile-time-checked sqlx queries,fse-cliparses the whole tables folder into aSchema, diffs it against the committed snapshot and emits plain sqlx migration files,- the snapshot file (
.fse/schema.json) is just this model as JSON.
Nothing in this crate knows about any concrete application: table names, column names and constraints all come from the parsed structs.
Re-exports§
pub use diff::Migration;pub use diff::diff_schemas;pub use model::ColumnDef;pub use model::DefaultValue;pub use model::EnumDef;pub use model::ForeignKey;pub use model::OnDelete;pub use model::RelationDef;pub use model::Schema;pub use model::SqlType;pub use model::TableDef;
Modules§
- diff
- Schema diffing: old snapshot + new structs → one migration file.
- model
- The schema model — the single source of truth for what a
#[derive(Table)]struct means in SQL. Everything isserde-serializable because the snapshot file is this model as JSON. - parse
- syn-based parsing of
#[derive(Table)]structs and#[derive(DbEnum)]enums into the schema model. This is the only place#[orm(...)]attribute semantics are defined — the derive macro and the CLI both call into here, so they can never drift apart. - snapshot
- The snapshot file (
.fse/schema.json): the schema state the last generated migration brought the database to. Committed to git so migration generation is deterministic and reviewable. - sql
- SQLite DDL generation from the schema model. Kept dialect-shaped (every statement goes through this module) so a second backend is a new module, not a rewrite.
Structs§
- Error
- A schema error: unparseable source, an unsupported type, an invalid attribute combination or an unresolvable reference. Always carries a message that names the offending struct/field so the CLI and the derive can surface it directly.