Skip to main content

Module parse

Module parse 

Source
Expand description

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.

Functions§

enum_from_item
Parse one #[derive(DbEnum)] enum. Variants must be unit variants; the stored value is the snake_case variant name.
has_derive
Does #[derive(...)] on this item mention name (by last path segment, so fse_orm::Table matches too)?
has_model_attr
Does the item carry the framework’s #[model(...)] attribute macro? Such a struct expands to #[derive(Table)] plus app metadata, so the schema layer treats it exactly like a hand-derived table. (The framework crates are not a dependency here — this is a purely syntactic check, in the same spirit as has_derive.)
native_sql_type
Map a Rust type to its native SQLite storage type. Anything not listed here needs #[orm(json)] or a DbEnum.
parse_sources
Parse a whole tables folder: sources is (file name, file content), where the file name is only used in error messages. Two passes — enums first so struct fields can resolve them — then foreign keys are resolved from struct names to table names.
parse_sources_with_external
Like parse_sources, but with additional already-known tables (module snapshots) available for foreign-key/relation resolution — so an app table can references(SomeModuleStruct) a table it doesn’t define. The external tables are not part of the returned schema.
pluralize
Naive English pluralization for default table names — struct Category becomes table categories. Wrong for irregular nouns; override with #[orm(table = "...")].
table_from_struct
Parse one #[derive(Table)] struct.
to_snake_case