Expand description
§vld-sea — SeaORM integration for vld
Validate ActiveModel fields before
insert() / update() hits the database.
§Approach
- Define a
vld::schema!that mirrors the entity columns you want validated. - Call
validate_active(extractsSet/Unchangedvalues from the ActiveModel into JSON and runs the schema). - Or call
validate_modelon anySerialize-able struct (e.g. an input DTO, or SeaORMModel). - Optionally hook into
ActiveModelBehavior::before_saveso validation runs automatically.
§Quick Start
ⓘ
use sea_orm::*;
use vld_sea::prelude::*;
vld::schema! {
#[derive(Debug)]
pub struct UserInput {
pub name: String => vld::string().min(1).max(100),
pub email: String => vld::string().email(),
}
}
// Before insert:
let am = user::ActiveModel {
name: Set("Alice".to_owned()),
email: Set("alice@example.com".to_owned()),
..Default::default()
};
vld_sea::validate_active::<UserInput, _>(&am)?;
am.insert(&db).await?;Re-exports§
Modules§
- prelude
- Prelude — import everything you need.
Macros§
- impl_
vld_ before_ save - Implements
ActiveModelBehaviorwith automatic vld validation inbefore_save.
Structs§
- Validated
- A wrapper that proves its inner value has been validated against schema
S.
Enums§
- VldSea
Error - Error returned by
vld-seaoperations.
Functions§
- active_
model_ to_ json - Convert an
ActiveModelto aserde_json::Valueobject. - before_
save - Helper for use inside
ActiveModelBehavior::before_save. - validate_
active - Validate an
ActiveModelagainst schemaS. - validate_
json - Parse and validate raw JSON against schema
S. - validate_
model - Validate a serializable value against schema
S.