Skip to main content

Crate vld_sea

Crate vld_sea 

Source
Expand description

§vld-sea — SeaORM integration for vld

Validate ActiveModel fields before insert() / update() hits the database.

§Approach

  1. Define a vld::schema! that mirrors the entity columns you want validated.
  2. Call validate_active (extracts Set/Unchanged values from the ActiveModel into JSON and runs the schema).
  3. Or call validate_model on any Serialize-able struct (e.g. an input DTO, or SeaORM Model).
  4. Optionally hook into ActiveModelBehavior::before_save so 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§

pub use sea_orm;
pub use vld;

Modules§

prelude
Prelude — import everything you need.

Macros§

impl_vld_before_save
Implements ActiveModelBehavior with automatic vld validation in before_save.

Structs§

Validated
A wrapper that proves its inner value has been validated against schema S.

Enums§

VldSeaError
Error returned by vld-sea operations.

Functions§

active_model_to_json
Convert an ActiveModel to a serde_json::Value object.
before_save
Helper for use inside ActiveModelBehavior::before_save.
validate_active
Validate an ActiveModel against schema S.
validate_json
Parse and validate raw JSON against schema S.
validate_model
Validate a serializable value against schema S.