derive_form
Procedural macros for the Runique web framework.
Exposes two macros:
model!(...)— DSL to declare a SeaORM model and generate its schema#[form(...)]— attribute macro to generate a form struct from a model schema
model!(...)
Declares a database model and generates the corresponding SeaORM entity, ActiveModel, relations, and a schema() function used by #[form(...)].
use model;
model!
Supported field types
String, i8, i16, i32, i64, u32, u64, f32, f64,
bool, date, time, datetime, timestamp, uuid, json, blob, enum(...), and more.
Field options
| Option | Description |
|---|---|
required / nullable |
NOT NULL vs NULL |
unique |
UNIQUE constraint |
index |
Create an index |
max_len(n) / min_len(n) |
Length constraints |
max(n) / min(n) |
Value constraints |
default(...) |
Default value |
auto_now |
Set to now() on insert |
auto_now_update |
Set to now() on update |
fk(table.col, cascade) |
Foreign key |
#[form(...)]
Generates a form struct from the schema produced by model!.
use form;
;
Parameters
| Parameter | Required | Description |
|---|---|---|
schema |
yes | Path to the schema function from model! |
fields |
no | Whitelist — only these fields are included |
exclude |
no | Blacklist — these fields are excluded |
fields and exclude are mutually exclusive. The primary key is always excluded.
What is generated
The generated struct implements:
ModelForm—schema(),fields(),exclude()RuniqueForm—register_fields(),from_form(),get_form(),get_form_mut()
It can be used directly with Runique's Prisme<T> extractor.
Usage with Runique
use *;
// 1. Declare the model
model!
// 2. Create a form from the schema
;
// 3. Use it in a handler
pub async
License
MIT — part of the Runique project.