pub trait Model: EntityTrait + Sized{
// Provided methods
fn all<'async_trait>( ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Model>, FrameworkError>> + Send + 'async_trait>>
where Self: Send + 'async_trait { ... }
fn find_by_pk<'async_trait, K>(
id: K,
) -> Pin<Box<dyn Future<Output = Result<Option<Self::Model>, FrameworkError>> + Send + 'async_trait>>
where K: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> + Send + 'async_trait,
Self: Send + 'async_trait { ... }
fn find_or_fail<'async_trait, K>(
id: K,
) -> Pin<Box<dyn Future<Output = Result<Self::Model, FrameworkError>> + Send + 'async_trait>>
where K: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> + Send + Debug + Copy + 'async_trait,
Self: Send + 'async_trait { ... }
fn count_all<'async_trait>( ) -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>
where Self: Send + 'async_trait { ... }
fn exists_any<'async_trait>( ) -> Pin<Box<dyn Future<Output = Result<bool, FrameworkError>> + Send + 'async_trait>>
where Self: Send + 'async_trait { ... }
fn first<'async_trait>( ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Model>, FrameworkError>> + Send + 'async_trait>>
where Self: Send + 'async_trait { ... }
}Expand description
Trait providing Laravel-like read operations on SeaORM entities
Implement this trait on your SeaORM Entity to get convenient static methods for querying records.
§Example
ⓘ
use ferro_rs::database::Model;
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub email: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
// Add Ferro's Model trait
impl ferro_rs::database::Model for Entity {}
// Now you can use:
let users = Entity::all().await?;
let user = Entity::find_by_pk(1).await?;Provided Methods§
Sourcefn all<'async_trait>() -> Pin<Box<dyn Future<Output = Result<Vec<Self::Model>, FrameworkError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
fn all<'async_trait>() -> Pin<Box<dyn Future<Output = Result<Vec<Self::Model>, FrameworkError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
Sourcefn find_by_pk<'async_trait, K>(
id: K,
) -> Pin<Box<dyn Future<Output = Result<Option<Self::Model>, FrameworkError>> + Send + 'async_trait>>where
K: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> + Send + 'async_trait,
Self: Send + 'async_trait,
fn find_by_pk<'async_trait, K>(
id: K,
) -> Pin<Box<dyn Future<Output = Result<Option<Self::Model>, FrameworkError>> + Send + 'async_trait>>where
K: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> + Send + 'async_trait,
Self: Send + 'async_trait,
Sourcefn find_or_fail<'async_trait, K>(
id: K,
) -> Pin<Box<dyn Future<Output = Result<Self::Model, FrameworkError>> + Send + 'async_trait>>where
K: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> + Send + Debug + Copy + 'async_trait,
Self: Send + 'async_trait,
fn find_or_fail<'async_trait, K>(
id: K,
) -> Pin<Box<dyn Future<Output = Result<Self::Model, FrameworkError>> + Send + 'async_trait>>where
K: Into<<Self::PrimaryKey as PrimaryKeyTrait>::ValueType> + Send + Debug + Copy + 'async_trait,
Self: Send + 'async_trait,
Sourcefn count_all<'async_trait>() -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
fn count_all<'async_trait>() -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
Sourcefn exists_any<'async_trait>() -> Pin<Box<dyn Future<Output = Result<bool, FrameworkError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
fn exists_any<'async_trait>() -> Pin<Box<dyn Future<Output = Result<bool, FrameworkError>> + Send + 'async_trait>>where
Self: Send + '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.