pub trait EntityTrait: IdenStatic + Default {
type Model: ModelTrait<Entity = Self> + FromQueryResult;
type Column: ColumnTrait;
type PrimaryKey: PrimaryKeyTrait + PrimaryKeyToColumn<Column = Self::Column>;
type ActiveModel: ActiveModelTrait<Entity = Self>;
type Relation: RelationTrait;
const TABLE_NAME: &'static str;
Show 13 methods
// Provided methods
fn table_name() -> &'static str { ... }
fn belongs_to<R: EntityTrait>(_: R) -> RelationBuilder<Self, R> { ... }
fn has_one<R: EntityTrait>(_: R) -> RelationBuilder<Self, R> { ... }
fn has_many<R: EntityTrait>(_: R) -> RelationBuilder<Self, R> { ... }
fn find() -> Select<Self> { ... }
fn find_by_id<T>(id: T) -> Select<Self>
where T: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> { ... }
fn insert<A: ActiveModelTrait<Entity = Self>>(model: A) -> Insert<A> { ... }
fn insert_many<A: ActiveModelTrait<Entity = Self>, I: IntoIterator<Item = A>>(
models: I,
) -> InsertMany<A> { ... }
fn update<A: ActiveModelTrait<Entity = Self>>(model: A) -> UpdateOne<A> { ... }
fn update_many() -> UpdateMany<Self> { ... }
fn delete<A: ActiveModelTrait<Entity = Self>>(model: A) -> DeleteOne<A> { ... }
fn delete_many() -> DeleteMany<Self> { ... }
fn delete_by_id<T>(id: T) -> DeleteMany<Self>
where T: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> { ... }
}Expand description
An entity: a table together with its model, columns, key and relations.
Derived by DeriveEntityModel; the unit struct Entity implements it.
Required Associated Constants§
Sourceconst TABLE_NAME: &'static str
const TABLE_NAME: &'static str
The table name.
Required Associated Types§
Sourcetype Model: ModelTrait<Entity = Self> + FromQueryResult
type Model: ModelTrait<Entity = Self> + FromQueryResult
The model struct.
Sourcetype Column: ColumnTrait
type Column: ColumnTrait
The column enum.
Sourcetype PrimaryKey: PrimaryKeyTrait + PrimaryKeyToColumn<Column = Self::Column>
type PrimaryKey: PrimaryKeyTrait + PrimaryKeyToColumn<Column = Self::Column>
The primary key enum.
Sourcetype ActiveModel: ActiveModelTrait<Entity = Self>
type ActiveModel: ActiveModelTrait<Entity = Self>
The active model struct.
Sourcetype Relation: RelationTrait
type Relation: RelationTrait
The relation enum.
Provided Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
The table name, as a method for contexts that cannot name the constant.
Sourcefn belongs_to<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>
fn belongs_to<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>
Starts a belongs_to relation, in which Self holds the foreign key.
Sourcefn has_one<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>
fn has_one<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>
Starts a has_one relation, in which R holds the foreign key.
Sourcefn has_many<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>
fn has_many<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>
Starts a has_many relation, in which R holds the foreign key.
Sourcefn find_by_id<T>(id: T) -> Select<Self>
fn find_by_id<T>(id: T) -> Select<Self>
Builds SELECT * FROM table WHERE pk = id.
Composite keys are passed as a tuple in key-column order.
Sourcefn insert<A: ActiveModelTrait<Entity = Self>>(model: A) -> Insert<A>
fn insert<A: ActiveModelTrait<Entity = Self>>(model: A) -> Insert<A>
Builds an INSERT of one active model.
Sourcefn insert_many<A: ActiveModelTrait<Entity = Self>, I: IntoIterator<Item = A>>(
models: I,
) -> InsertMany<A>
fn insert_many<A: ActiveModelTrait<Entity = Self>, I: IntoIterator<Item = A>>( models: I, ) -> InsertMany<A>
Builds a single INSERT of several active models.
Sourcefn update<A: ActiveModelTrait<Entity = Self>>(model: A) -> UpdateOne<A>
fn update<A: ActiveModelTrait<Entity = Self>>(model: A) -> UpdateOne<A>
Builds an UPDATE of one active model, matched by primary key.
Sourcefn update_many() -> UpdateMany<Self>
fn update_many() -> UpdateMany<Self>
Builds an UPDATE over many rows.
Sourcefn delete<A: ActiveModelTrait<Entity = Self>>(model: A) -> DeleteOne<A>
fn delete<A: ActiveModelTrait<Entity = Self>>(model: A) -> DeleteOne<A>
Builds a DELETE of one active model, matched by primary key.
Sourcefn delete_many() -> DeleteMany<Self>
fn delete_many() -> DeleteMany<Self>
Builds a DELETE over many rows.
Sourcefn delete_by_id<T>(id: T) -> DeleteMany<Self>
fn delete_by_id<T>(id: T) -> DeleteMany<Self>
Builds a DELETE matched by primary key.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".