Skip to main content

Model

Derive Macro Model 

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

Derive Model metadata for a struct.

§Example

use pgorm::Model;

#[derive(Model)]
#[orm(table = "users")]
struct User {
    #[orm(id)]
    user_id: i64,
    username: String,
    email: Option<String>,
}

§Generated

  • TABLE: &'static str - Table name
  • COL_*: &'static str - Column name constants
  • SELECT_LIST: &'static str - Comma-separated column list
  • fn select_list_as(alias: &str) -> String - Aliased column list for JOINs

§Attributes

  • #[orm(table = "name")] - Specify table name (required)
  • #[orm(id)] - Mark field as primary key
  • #[orm(column = "name")] - Map field to different column name