Derive Macro SqlHelper

Source
#[derive(SqlHelper)]
{
    // Attributes available to this derive:
    #[id]
    #[field_name]
    #[create_time]
    #[update_time]
}
Expand description

自动生成mysql数据库增删改查方法

基于sqlx生成findlistdeleteaddupdatesave_or_updatenewnew_commonbase_pagebase_count等方法。

需要在struct上下文中引入sqlx的db对象。

use super::db;

§Examples

#[derive(SqlHelper)]
pub struct Person {
    #[id]
    pub id: i32,
    pub name: String,
    pub age: i32,
    pub weight: Option<i32>,
    #[create_time]
    pub create_time: NaiveDateTime,
    #[update_time]
    pub update_time: NaiveDateTime,
}