Skip to main content

Crate djogi_macros

Crate djogi_macros 

Source
Expand description

Proc macros for the Djogi framework. Provides:

  • #[model(table = "...")] — the attribute macro that does field injection and derives all Model impls.
  • reverse_one_to_many! / reverse_one_to_one! — function-like macros emitting reverse-relation accessor methods on the target model plus an inventory::submit! registration record.
  • many_to_many! — function-like macro emitting one direction of a many-to-many relation: the ManyToMany<Target> trait impl, a named inherent accessor on the source type, and an inventory::submit! registration record.
  • djogi_main!(…) — function-like macro generating fn 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 to djogi_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 its KIND / SQL_TYPE / DEFAULT_SQL associated consts), ToSql / FromSql delegation to the inner type, and optionally PrimaryKeyDbGen (when bulk_sql = "..." is set) or PrimaryKeyClientGen (when generate = |...| expr is 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 through djogi and:
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 the ModelDescriptor the migration differ consumes.
trait_impl
#[djogi::trait_impl] — trait-registry attribute. Wraps a trait impl block so cross-cutting consumers (Sassi::all_impl::<dyn T>) can iterate every model that implements the trait at runtime without enumerating each impl site by hand.

Derive Macros§

DjogiEnum
Derive typed Postgres enum support. Emits postgres_types::ToSql + FromSql impls that encode/decode the enum as its mapped Postgres string label, plus an inventory::submit! of an EnumDescriptor for the migration differ.
JsonbSchema
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 a JsonbPathRef<M, FieldType> ready for comparison. All other field types are assumed to implement JsonbSchema and their method returns the nested type’s Path<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: Only field and derived are listed as helper attributes here, not model. Listing model as a helper would shadow the #[model] proc_macro_attribute and cause ambiguous resolution (Post-Review Fix #4).