Skip to main content

Entity

Derive Macro Entity 

Source
#[derive(Entity)]
{
    // Attributes available to this derive:
    #[table]
    #[column]
}
Expand description

Derive macro: auto-generates an sz_orm_core::Model trait impl.

Requires the struct to have exactly one #[column(primary_key)] field; that field’s type becomes Model::PrimaryKey.

§Supported attributes

  • #[table(name = "...")] — specifies the table name, defaults to the snake_case struct name
  • #[column(primary_key)] — marks the primary key field (required, exactly one)
  • #[column(name = "...")] — overrides the primary key column name (defaults to the field name)

§Example

use sz_orm_macros::Entity;

#[derive(Entity)]
#[table(name = "users")]
struct User {
    #[column(primary_key)]
    id: i64,
    name: String,
}

assert_eq!(User::table_name(), "users");
assert_eq!(User::pk_name(), "id");