Crates.io | sea-orm-field-updater |
lib.rs | sea-orm-field-updater |
version | 0.0.2 |
source | src |
created_at | 2022-05-23 06:43:04.258743 |
updated_at | 2022-06-08 10:04:11.582748 |
description | update model by field |
homepage | |
repository | https://github.com/rise0chen/sea-orm-field-updater.git |
max_upload_size | |
id | 591611 |
size | 16,115 |
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
}
}