Skip to main content

Repository

Trait Repository 

Source
pub trait Repository<E: Entity + FromRow>: Send + Sync {
    // Required methods
    async fn find_by_id(&self, id: E::Id) -> DatabaseResult<Option<E>>;
    async fn find_all(&self) -> DatabaseResult<Vec<E>>;
    async fn find_by(&self, condition: Condition) -> DatabaseResult<Vec<E>>;
    async fn find_one(&self, condition: Condition) -> DatabaseResult<Option<E>>;
    async fn insert(&self, entity: &E) -> DatabaseResult<i64>
       where E: ToRow;
    async fn update(&self, entity: &E) -> DatabaseResult<u64>
       where E: ToRow;
    async fn delete_by_id(&self, id: E::Id) -> DatabaseResult<u64>;
    async fn delete_by(&self, condition: Condition) -> DatabaseResult<u64>;
    async fn count(&self) -> DatabaseResult<u64>;
    async fn count_by(&self, condition: Condition) -> DatabaseResult<u64>;
    async fn exists(&self, id: E::Id) -> DatabaseResult<bool>;
}
Expand description

仓储 trait - 提供 CRUD 操作

Required Methods§

Source

async fn find_by_id(&self, id: E::Id) -> DatabaseResult<Option<E>>

根据主键查找

Source

async fn find_all(&self) -> DatabaseResult<Vec<E>>

查找所有

Source

async fn find_by(&self, condition: Condition) -> DatabaseResult<Vec<E>>

根据条件查找

Source

async fn find_one(&self, condition: Condition) -> DatabaseResult<Option<E>>

根据条件查找一条

Source

async fn insert(&self, entity: &E) -> DatabaseResult<i64>
where E: ToRow,

插入实体

Source

async fn update(&self, entity: &E) -> DatabaseResult<u64>
where E: ToRow,

更新实体

Source

async fn delete_by_id(&self, id: E::Id) -> DatabaseResult<u64>

根据主键删除

Source

async fn delete_by(&self, condition: Condition) -> DatabaseResult<u64>

根据条件删除

Source

async fn count(&self) -> DatabaseResult<u64>

统计数量

Source

async fn count_by(&self, condition: Condition) -> DatabaseResult<u64>

根据条件统计

Source

async fn exists(&self, id: E::Id) -> DatabaseResult<bool>

检查是否存在

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§

Source§

impl<E: Entity + FromRow> Repository<E> for DbRepository<E>

Available on crate feature turso only.