Skip to main content

Model

Trait Model 

Source
pub trait Model:
    Sized
    + Send
    + Sync
    + Unpin
    + 'static {
Show 13 methods // Required methods fn table_name() -> &'static str; fn columns() -> &'static [&'static str]; // Provided methods fn primary_key() -> &'static str { ... } fn query() -> QueryBuilder<Self> { ... } fn find<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>> where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait { ... } fn find_or_fail<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Self>> + Send + 'async_trait>> where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait { ... } fn find_many<'life0, 'life1, 'async_trait>( ids: &'life0 [i64], pool: &'life1 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + 'async_trait>> where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn all<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + 'async_trait>> where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait { ... } fn first<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>> where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait { ... } fn last<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>> where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait { ... } fn count<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<i64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn any<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn exists<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

Главный трейт, который реализует каждая модель. Генерируется #[derive(Model)].

Required Methods§

Source

fn table_name() -> &'static str

Имя таблицы в БД.

Source

fn columns() -> &'static [&'static str]

Список всех колонок таблицы (в порядке SELECT *).

Provided Methods§

Source

fn primary_key() -> &'static str

Имя первичного ключа.

Source

fn query() -> QueryBuilder<Self>

Создаёт QueryBuilder для данной модели.

Source

fn find<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait,

SELECT * FROM table WHERE pk = id

Source

fn find_or_fail<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Self>> + Send + 'async_trait>>
where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait,

Как find, но возвращает OrmError::NotFound если запись не найдена.

Source

fn find_many<'life0, 'life1, 'async_trait>( ids: &'life0 [i64], pool: &'life1 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + 'async_trait>>
where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Находит несколько записей по списку id.

Source

fn all<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + 'async_trait>>
where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait,

Все записи таблицы.

Source

fn first<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait,

Первая запись (по PK ASC).

Source

fn last<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
where Self: for<'r> FromRow<'r, PgRow> + 'async_trait, 'life0: 'async_trait,

Последняя запись (по PK DESC).

Source

fn count<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<i64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Количество записей.

Source

fn any<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Есть ли хоть одна запись.

Source

fn exists<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Существует ли запись с данным id.

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§