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.praxschema fileModel- 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 targetingaggregate. Acceptswhere:,_count:,_sum:,_avg:,_min:,_max:keys. At least one aggregate key is required.- count
prax::count!— schema-aware DSL targetingcount. Phase 3 only supports thewhere:key; the Prisma-style_countaggregate (select: { _count: { posts: true } }) is phase 6.- create
prax::create!— schema-aware DSL targetingcreate. Top-level keys:data:(required),includexorselect. Phase 5a is scalar-only — relation operators insidedata:(nested writes) land in phase 5b.- create_
many prax::create_many!— schema-aware DSL targetingcreate_many. Top-level keys:data:(required list of blocks),skip_duplicates:(optional bool).- cursor
prax::cursor!— schema-aware shape macro returning a<Model>WhereUniqueInputvalue for use as acursor:argument to the read macros.- delete
prax::delete!— schema-aware DSL targetingdelete. Thewhere:block must match a unique column.- delete_
many prax::delete_many!— schema-aware DSL targetingdelete_many. Thewhere:block is the non-unique form.- find_
first prax::find_first!— schema-aware DSL targetingfind_first.- find_
many prax::find_many!— schema-aware declarative DSL for the fluent-builder’sfind_manyoperation. See spec §4 for the full grammar.- find_
unique prax::find_unique!— schema-aware DSL targetingfind_unique. Thewhere:block must match a single@unique(or@id) column.- group_
by prax::group_by!— schema-aware DSL targetinggroup_by_columns. Acceptsby:(required),where:,_count:,_sum:,_avg:,_min:,_max:, andhaving:keys.- include
prax::include!— schema-aware shape macro returning a<Model>Includevalue. Composes with the read macros via..spreadto build reusable relation-include shapes.- order_
by prax::order_by!— schema-aware shape macro returning anOrderByvalue. 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>Selectvalue. Composes with the read macros via..spread.- update
prax::update!— schema-aware DSL targetingupdate. Top-level keys:where:(required, unique),data:(required),includexorselect. Atomic operators (increment,decrement,multiply,divide,unset) work via{ <op>: V }blocks insidedata:— see spec §4.- update_
many prax::update_many!— schema-aware DSL targetingupdate_many. Top-level keys:where:(optional non-unique filter),data:(required).- upsert
prax::upsert!— schema-aware DSL targetingupsert. Top-level keys:where:(required, unique),create:(required),update:(required),includexorselect. On hit applies theupdate:payload; on miss inserts thecreate:payload.- where
prax::r#where!— schema-aware shape macro returning a<Model>WhereInputvalue. Composes with the read macros via..spread:
Derive Macros§
- Model
- Derive macro for defining Prax models manually.