vld-sea
SeaORM integration for the vld validation library.
Validate ActiveModel fields before insert() / update() hits the database.
Features
validate_active— extractSet/Unchangedvalues fromActiveModelinto JSON and validatevalidate_model— validate anySerialize-able struct (Model, DTO, etc.)validate_json— validate raw JSONValidated<S, T>— wrapper proving data has been validatedbefore_save— helper forActiveModelBehavior::before_saveimpl_vld_before_save!— macro for automatic validation on every insert/updateactive_model_to_json— convert ActiveModel to JSON (skipsNotSetfields)
Installation
[]
= "0.1"
= "0.1"
= "1"
Quick Start
1. Define the validation schema
schema!
2. Validate ActiveModel before insert
use Set;
let am = ActiveModel ;
// Validate — returns parsed schema or VldSeaError
?;
// Now safe to insert
am.insert.await?;
3. Automatic validation via before_save
Option A — manual:
Option B — macro:
// Replace the default `impl ActiveModelBehavior for ActiveModel {}`
impl_vld_before_save!;
Option C — separate schemas for insert vs update:
impl_vld_before_save!;
4. Validate a DTO
let input = NewUser ;
?;
ActiveModel → JSON
active_model_to_json converts an ActiveModel to a JSON object. Only Set and Unchanged fields are included; NotSet fields are omitted.
Supported SQL types: bool, i8–i64, u8–u64, f32, f64, String, char.
Feature-gated types (chrono, uuid, etc.) are mapped to null.
Running Examples
License
MIT