Skip to main content

EntityTrait

Trait EntityTrait 

Source
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§

Source

const TABLE_NAME: &'static str

The table name.

Required Associated Types§

Source

type Model: ModelTrait<Entity = Self> + FromQueryResult

The model struct.

Source

type Column: ColumnTrait

The column enum.

Source

type PrimaryKey: PrimaryKeyTrait + PrimaryKeyToColumn<Column = Self::Column>

The primary key enum.

Source

type ActiveModel: ActiveModelTrait<Entity = Self>

The active model struct.

Source

type Relation: RelationTrait

The relation enum.

Provided Methods§

Source

fn table_name() -> &'static str

The table name, as a method for contexts that cannot name the constant.

Source

fn belongs_to<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>

Starts a belongs_to relation, in which Self holds the foreign key.

Source

fn has_one<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>

Starts a has_one relation, in which R holds the foreign key.

Source

fn has_many<R: EntityTrait>(_: R) -> RelationBuilder<Self, R>

Starts a has_many relation, in which R holds the foreign key.

Source

fn find() -> Select<Self>

Builds SELECT * FROM table.

Source

fn find_by_id<T>(id: T) -> Select<Self>
where T: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType>,

Builds SELECT * FROM table WHERE pk = id.

Composite keys are passed as a tuple in key-column order.

Source

fn insert<A: ActiveModelTrait<Entity = Self>>(model: A) -> Insert<A>

Builds an INSERT of one active model.

Source

fn insert_many<A: ActiveModelTrait<Entity = Self>, I: IntoIterator<Item = A>>( models: I, ) -> InsertMany<A>

Builds a single INSERT of several active models.

Source

fn update<A: ActiveModelTrait<Entity = Self>>(model: A) -> UpdateOne<A>

Builds an UPDATE of one active model, matched by primary key.

Source

fn update_many() -> UpdateMany<Self>

Builds an UPDATE over many rows.

Source

fn delete<A: ActiveModelTrait<Entity = Self>>(model: A) -> DeleteOne<A>

Builds a DELETE of one active model, matched by primary key.

Source

fn delete_many() -> DeleteMany<Self>

Builds a DELETE over many rows.

Source

fn delete_by_id<T>(id: T) -> DeleteMany<Self>
where T: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType>,

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".

Implementors§