Skip to main content

Crate turso_orm_macros

Crate turso_orm_macros 

Source
Expand description

Macros: the derive macros that generate entity, relation, identifier and row-decoding impls for turso-orm.

The macros are re-exported by turso_orm behind its macros feature and by turso_orm_migration; they are not meant to be used from this crate directly, because the code they expand to refers to ::turso_orm::... paths and to the __private module that crate exposes for generated code only.

Each derive lives in its own module with a single expand function that takes the parsed input and returns either the generated tokens or a syn::Error carrying the span of the offending item, so that users see the error on their own code rather than inside the macro. Attribute parsing is shared through the attrs module.

  • DeriveEntityModel expands a Model struct into Entity, Column, PrimaryKey and ActiveModel plus their trait impls.
  • DeriveRelation expands a Relation enum into RelationTrait and Related<R> impls, junction tables included.
  • DeriveActiveEnum makes a fieldless enum a column type.
  • DerivePartialModel makes a struct a self-selecting projection.
  • DeriveIntoActiveModel converts a plain struct into an active model.
  • DeriveIden implements the identifier traits on a unit struct or a fieldless enum.
  • FromQueryResult implements row decoding for a plain struct.
  • DeriveMigrationName names a migration after its module.

Derive Macros§

DeriveActiveEnum
Derives ActiveEnum and the column-type impls for a fieldless enum.
DeriveEntityModel
Derives an entity from a Model struct.
DeriveIden
Derives IdenStatic and the SQL identifier traits for a unit struct or a fieldless enum.
DeriveIntoActiveModel
Derives IntoActiveModel for a plain struct whose fields are a subset of an entity’s columns.
DeriveMigrationName
Derives MigrationName from the module path.
DerivePartialModel
Derives PartialModelTrait and FromQueryResult for a projection struct.
DeriveRelation
Derives RelationTrait and Related<R> impls from a Relation enum.
FromQueryResult
Derives FromQueryResult for a plain struct.