Skip to main content

Entity

Derive Macro Entity 

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

Derive Entity for a #[derive(FromRow)] struct (see repository). Derive id_effect_sql::Entity (map a #[derive(FromRow)] struct to a table for Repository<T>; id_effect_sql feature repository).

Use it through the re-export id_effect_sql::Entity; the generated impl names ::id_effect_sql unless overridden with #[entity(crate = path)].

  • Container: table = ".." (default: the type name in snake case), tenant = "col", soft_delete = "col", scope = path (a fn() -> impl Into<Condition>, repeatable).
  • Fields: exactly one #[entity(id)] (#[entity(id, generated)] when the database assigns it) and at most one #[entity(version)] integer (optimistic locking). Columns are the FromRow columns; #[from_row(flatten)] fields are rejected.
ⓘ
use id_effect_sql::{Entity, FromRow};

#[derive(FromRow, Entity)]
#[entity(table = "accounts", tenant = "org_id", soft_delete = "deleted_at")]
struct Account {
  #[entity(id, generated)]
  id: i64,
  name: String,
  #[entity(version)]
  version: i64,
}