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§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Имя таблицы в БД.
Provided Methods§
Sourcefn primary_key() -> &'static str
fn primary_key() -> &'static str
Имя первичного ключа.
Sourcefn query() -> QueryBuilder<Self>
fn query() -> QueryBuilder<Self>
Создаёт QueryBuilder для данной модели.
Sourcefn find<'life0, 'async_trait>(
id: i64,
pool: &'life0 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
fn find<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
SELECT * FROM table WHERE pk = id
Sourcefn find_or_fail<'life0, 'async_trait>(
id: i64,
pool: &'life0 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<Self>> + Send + 'async_trait>>
fn find_or_fail<'life0, 'async_trait>( id: i64, pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Self>> + Send + 'async_trait>>
Как find, но возвращает OrmError::NotFound если запись не найдена.
Sourcefn find_many<'life0, 'life1, 'async_trait>(
ids: &'life0 [i64],
pool: &'life1 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + '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>>
Находит несколько записей по списку id.
Sourcefn all<'life0, 'async_trait>(
pool: &'life0 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + 'async_trait>>
fn all<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Vec<Self>>> + Send + 'async_trait>>
Все записи таблицы.
Sourcefn first<'life0, 'async_trait>(
pool: &'life0 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
fn first<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
Первая запись (по PK ASC).
Sourcefn last<'life0, 'async_trait>(
pool: &'life0 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
fn last<'life0, 'async_trait>( pool: &'life0 PgPool, ) -> Pin<Box<dyn Future<Output = OrmResult<Option<Self>>> + Send + 'async_trait>>
Последняя запись (по PK DESC).
Sourcefn 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 count<'life0, 'async_trait>(
pool: &'life0 PgPool,
) -> Pin<Box<dyn Future<Output = OrmResult<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Количество записей.
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.