Expand description
Proc macros for the Djogi framework. Provides:
#[model(table = "...")]— the attribute macro that does field injection and derives allModelimpls.reverse_one_to_many!/reverse_one_to_one!— function-like macros emitting reverse-relation accessor methods on the target model plus aninventory::submit!registration record.many_to_many!— function-like macro emitting one direction of a many-to-many relation: theManyToMany<Target>trait impl, a named inherent accessor on the source type, and aninventory::submit!registration record.djogi_main!(…)— function-like macro generatingfn main()that references model types to prevent LTO linker from dropping inventory data.link_anchor!()— per-crate fallback emitting a#[used]static + callable fn that forces a model crate into the linkage graph.#[derive(Model)]is a no-op stub kept for potential future use.
Macros§
- apps
- Declare the crate’s compile-time schema ownership domains.
djogi::apps!takes a block of unit-struct declarations, each carrying an#[app(...)]attribute describing the database target and (optionally) an explicit label: - djogi_
main - Generate a
fn main()that references model types to prevent the LTO linker from dropping inventory data, then delegates todjogi_cli::run_from_env(). Referencing a single descriptor per crate forces ALL inventory from that crate into the final binary. This macro makes that reference explicit and auditable at the adopter’s binary entry point. - link_
anchor - Emit a once-per-crate linkage anchor so an adopter binary can force
link-time retention of THIS crate’s
#[derive(Model)]registrations without listing every model type (#370, branch b). - many_
to_ many - Emit one direction of a many-to-many relation — the
ManyToMany<Target>trait impl, the named inherent accessor on the source type, and an inventory marker for . Invocation form: - primary_
key - Declarative-style macro for declaring custom primary-key types.
Emits a
pub struct <Name>(<Inner>);newtype plus the trait impls the#[model(pk = <Name>)]attribute relies on —PrimaryKey(with itsKIND/SQL_TYPE/DEFAULT_SQLassociated consts),ToSql/FromSqldelegation to the inner type, and optionallyPrimaryKeyDbGen(whenbulk_sql = "..."is set) orPrimaryKeyClientGen(whengenerate = |...| expris set). - reverse_
one_ to_ many - Emit a reverse one-to-many accessor on a model. Invocation form:
- reverse_
one_ to_ one - Emit a reverse one-to-one accessor on a model. Invocation form:
Attribute Macros§
- deliberately_
bypass_ convention_ with_ raw_ sql - Brings
djogi::__bypass::{RawAccessExt, RawPoolAccessExt}into scope for the decorated item, unlocking direct access to djogi’s raw SQL escape hatches at explicit, auditable sites. - djogi_
test - Per-test database lifecycle harness.
Transforms an
async fn my_test(ctx: DjogiContext)into a plain#[test]wrapper that builds a Tokio runtime throughdjogiand: - model
- The primary Djogi macro. Annotate any struct with
#[model(table = "...")]to inject framework fields (id,created_at,updated_at) and derive CRUD,FromRow, and theModelDescriptorthe migration differ consumes. - trait_
impl #[djogi::trait_impl]— trait-registry attribute. Wraps a traitimplblock so cross-cutting consumers (Sassi::all_impl::<dyn T>) can iterate every model that implements the trait at runtime without enumerating eachimplsite by hand.
Derive Macros§
- Djogi
Enum - Derive typed Postgres enum support.
Emits
postgres_types::ToSql+FromSqlimpls that encode/decode the enum as its mapped Postgres string label, plus aninventory::submit!of anEnumDescriptorfor the migration differ. - Jsonb
Schema - Derive the typed JSONB deep-path API for a schema struct.
Applying this derive to a named struct causes the macro to emit a
{T}Path<M>struct with one method per field. Scalar fields (from the cast-matrix allowlist:i16,i32,i64,f32,f64,bool,String,time::OffsetDateTime,time::Date,uuid::Uuid,rust_decimal::Decimal,serde_json::Value,HeerId,RanjId) return aJsonbPathRef<M, FieldType>ready for comparison. All other field types are assumed to implementJsonbSchemaand their method returns the nested type’sPath<M>with the path accumulator extended. - Model
- No-op stub — field injection requires
#[model](attribute macro). Kept as a placeholder for future derive-based extensions, and as the registration site for helper attributes that adopters write on the derived struct. NOTE: Onlyfieldandderivedare listed as helper attributes here, notmodel. Listingmodelas a helper would shadow the#[model]proc_macro_attribute and cause ambiguous resolution (Post-Review Fix #4).