Skip to main content

Entity

Trait Entity 

Source
pub trait Entity:
    Sized
    + Send
    + Sync
    + Debug
    + Display {
    type Id: Copy + PartialEq + Debug + Display + Send + Sync + 'static;

    // Required methods
    fn table_name() -> &'static str;
    fn id(&self) -> Self::Id;

    // Provided method
    fn query() -> TypedQueryBuilder<Self> { ... }
}
Expand description

Core entity trait that all database models must implement

Required Associated Types§

Source

type Id: Copy + PartialEq + Debug + Display + Send + Sync + 'static

The ID type for this entity (e.g., Uuid, i64)

Required Methods§

Source

fn table_name() -> &'static str

The table name in the database

Source

fn id(&self) -> Self::Id

Get the entity’s ID

Provided Methods§

Source

fn query() -> TypedQueryBuilder<Self>

Start building a type-safe query for this entity

§Example
let users = User::query()
    .filter(User::email().eq("user@example.com"))
    .fetch_all(pool)
    .await?;

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§