Skip to main content

AuthEntity

Derive Macro AuthEntity 

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

Derive macro that generates Auth* trait impls and Sqlx*Model impls for a SQLx model.

§Usage

Annotate a struct deriving sqlx::FromRow with #[derive(AuthEntity)] and #[auth(role = "...")] where role is one of user, session, account, or verification. table = "..." names the physical table and defaults to the bundled table for the role. Physical column names follow #[sqlx(rename = "...")] and #[sqlx(rename_all = "...")]. id_generator = "path::to::function" selects a String ID factory; the default remains a UUID. Use #[auth(column_type = "bpchar")] on String fields mapped to PostgreSQL CHAR(n) to retain typed parameters and indexed equality.

ⓘ
#[derive(Clone, Debug, serde::Serialize, sqlx::FromRow, AuthEntity)]
#[auth(role = "user", table = "users")]
pub struct User {
    pub id: String,
    // ... core fields ...
}

§Extra fields

The struct may contain fields beyond the core set required by the auth role. They are omitted from generated inserts, so the database default applies. Every field type implements SqlxValue; override the inferred column category with #[auth(column_type = "text")].