Trait Service

Source
pub trait Service:
    Send
    + Sized
    + Entity
    + FromRow
    + 'static {
    // Required method
    fn set_primary_key(&mut self, id: u64);

    // Provided methods
    async fn query(query_sql: String) -> Result<Vec<Self>, BoxErr> { ... }
    async fn jpa_query(
        query_sql: String,
        params: Params,
    ) -> Result<Vec<Self>, BoxErr> { ... }
    async fn list() -> Result<Vec<Self>, BoxErr> { ... }
    async fn find_by_id(id: u64) -> Result<Option<Self>, BoxErr> { ... }
    async fn add(self) -> Result<Self, BoxErr> { ... }
    async fn edit(self) -> Result<Self, BoxErr> { ... }
    async fn remove(id: u64) -> Result<(), BoxErr> { ... }
}

Required Methods§

Source

fn set_primary_key(&mut self, id: u64)

设置主键值

Provided Methods§

Source

async fn query(query_sql: String) -> Result<Vec<Self>, BoxErr>

自定义SQL查询

Source

async fn jpa_query( query_sql: String, params: Params, ) -> Result<Vec<Self>, BoxErr>

自定义JPA SQL查询

Source

async fn list() -> Result<Vec<Self>, BoxErr>

获取列表

Source

async fn find_by_id(id: u64) -> Result<Option<Self>, BoxErr>

根据主键单条查询

Source

async fn add(self) -> Result<Self, BoxErr>

将当前Entity对象插入数据库

Source

async fn edit(self) -> Result<Self, BoxErr>

将当前Entity对象根据主键进行数据更新(不包含None值的字段)

Source

async fn remove(id: u64) -> Result<(), BoxErr>

根据主键单条删除

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§