Skip to main content

InsertModel

Derive Macro InsertModel 

Source
#[derive(InsertModel)]
{
    // Attributes available to this derive:
    #[orm]
}
Expand description

Derive InsertModel helpers for inserting into a table.

ยงAttributes

Struct-level:

  • #[orm(table = "name")] - Specify table name (required)
  • #[orm(returning = "TypePath")] - Enable insert_returning helpers (optional)
  • Conflict handling (Postgres ON CONFLICT):
    • #[orm(conflict_target = "col1,col2")] - conflict target columns (optional)
    • #[orm(conflict_constraint = "constraint_name")] - conflict constraint (optional)
    • #[orm(conflict_update = "col1,col2")] - columns to update on conflict (optional)
  • Multi-table write graphs (advanced): function-style attrs like #[orm(has_many(...))], #[orm(belongs_to(...))], #[orm(before_insert(...))]. See docs/design/multi-table-writes-final.md.

Field-level:

  • #[orm(id)] - Mark field as primary key (optional)
  • #[orm(skip_insert)] - Never include this field in INSERT
  • #[orm(default)] - Use SQL DEFAULT for this field
  • #[orm(auto_now_add)] - Use NOW() for this field on insert
  • #[orm(column = "name")] / #[orm(table = "name")] - Override column/table mapping (optional)