Skip to main content

Crate prax_codegen

Crate prax_codegen 

Source
Expand description

Procedural macros for the Prax ORM.

This crate provides compile-time code generation for Prax, transforming schema definitions into type-safe Rust code.

§Macros

  • prax_schema! - Generate models from a .prax schema file
  • Model - Derive macro for manual model definition

§Plugins

Code generation can be extended with plugins enabled via environment variables:

# Enable debug information
PRAX_PLUGIN_DEBUG=1 cargo build

# Enable JSON Schema generation
PRAX_PLUGIN_JSON_SCHEMA=1 cargo build

# Enable GraphQL SDL generation
PRAX_PLUGIN_GRAPHQL=1 cargo build

# Enable custom serialization helpers
PRAX_PLUGIN_SERDE=1 cargo build

# Enable runtime validation
PRAX_PLUGIN_VALIDATOR=1 cargo build

# Enable all plugins
PRAX_PLUGINS_ALL=1 cargo build

§Example

// Generate models from schema file
prax::prax_schema!("schema.prax");

// Or manually define with derive macro
#[derive(prax::Model)]
#[prax(table = "users")]
struct User {
    #[prax(id, auto)]
    id: i32,
    #[prax(unique)]
    email: String,
    name: Option<String>,
}

Macros§

aggregate
prax::aggregate! — schema-aware DSL targeting aggregate. Accepts where:, _count:, _sum:, _avg:, _min:, _max: keys. At least one aggregate key is required.
count
prax::count! — schema-aware DSL targeting count. Phase 3 only supports the where: key; the Prisma-style _count aggregate (select: { _count: { posts: true } }) is phase 6.
create
prax::create! — schema-aware DSL targeting create. Top-level keys: data: (required), include xor select. Phase 5a is scalar-only — relation operators inside data: (nested writes) land in phase 5b.
create_many
prax::create_many! — schema-aware DSL targeting create_many. Top-level keys: data: (required list of blocks), skip_duplicates: (optional bool).
cursor
prax::cursor! — schema-aware shape macro returning a <Model>WhereUniqueInput value for use as a cursor: argument to the read macros.
delete
prax::delete! — schema-aware DSL targeting delete. The where: block must match a unique column.
delete_many
prax::delete_many! — schema-aware DSL targeting delete_many. The where: block is the non-unique form.
find_first
prax::find_first! — schema-aware DSL targeting find_first.
find_many
prax::find_many! — schema-aware declarative DSL for the fluent-builder’s find_many operation. See spec §4 for the full grammar.
find_unique
prax::find_unique! — schema-aware DSL targeting find_unique. The where: block must match a single @unique (or @id) column.
group_by
prax::group_by! — schema-aware DSL targeting group_by_columns. Accepts by: (required), where:, _count:, _sum:, _avg:, _min:, _max:, and having: keys.
include
prax::include! — schema-aware shape macro returning a <Model>Include value. Composes with the read macros via ..spread to build reusable relation-include shapes.
order_by
prax::order_by! — schema-aware shape macro returning an OrderBy value. Accepts either a single { field: dir } block or a list of such blocks for multi-key sorts.
prax_schema
Generate models from a Prax schema file.
select
prax::select! — schema-aware shape macro returning a <Model>Select value. Composes with the read macros via ..spread.
update
prax::update! — schema-aware DSL targeting update. Top-level keys: where: (required, unique), data: (required), include xor select. Atomic operators (increment, decrement, multiply, divide, unset) work via { <op>: V } blocks inside data: — see spec §4.
update_many
prax::update_many! — schema-aware DSL targeting update_many. Top-level keys: where: (optional non-unique filter), data: (required).
upsert
prax::upsert! — schema-aware DSL targeting upsert. Top-level keys: where: (required, unique), create: (required), update: (required), include xor select. On hit applies the update: payload; on miss inserts the create: payload.
where
prax::r#where! — schema-aware shape macro returning a <Model>WhereInput value. Composes with the read macros via ..spread:

Derive Macros§

Model
Derive macro for defining Prax models manually.