sea-orm-field-updater

Crates.iosea-orm-field-updater
lib.rssea-orm-field-updater
version0.0.2
sourcesrc
created_at2022-05-23 06:43:04.258743
updated_at2022-06-08 10:04:11.582748
descriptionupdate model by field
homepage
repositoryhttps://github.com/rise0chen/sea-orm-field-updater.git
max_upload_size
id591611
size16,115
Rise Chen (rise0chen)

documentation

README

sea-orm-field-updater

Provides FieldUpdater derive macro.

#[derive(FieldUpdater)]
#[derive(DeriveEntityModel)]
#[derive(StructField)]
#[derive(Debug, Clone, PartialEq)]
#[sea_orm(table_name = "task")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: u32,
    pub finish_at: Option<DateTime>,
}

generates

impl Model {
    pub fn str2col(s: &str) -> Option<Column> {
        match s {
            "id" => Some(Column::Id),
            "finish_at" => Some(Column::FinishAt),
            _ => None,
        }
    }
    pub fn field2cv(field: ModelField) -> (Column, SimpleExpr) {
        match field {
            ModelField::id(v) => (Column::Id, Expr::value(v)),
            ModelField::finish_at(v) => (Column::FinishAt, Expr::value(v)),
        }
    }
    pub fn fields2active(fields: Vec<ModelField>) -> ActiveModel {
        let mut model = ActiveModel::new();
        for field in fields {
            match field {
                ModelField::id(v) => model.id = Set(v),
                ModelField::finish_at(v) => model.finish_at = Set(v),
            }
        }
        model
    }
}
Commit count: 2

cargo fmt