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§
Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
The table name in the database
Provided Methods§
Sourcefn query() -> TypedQueryBuilder<Self>
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.