Skip to main content

Crate vld_sqlx

Crate vld_sqlx 

Source
Expand description

§vld-sqlx — SQLx integration for the vld validation library

Validate data before inserting into the database, and use strongly-typed validated column types with SQLx.

§Quick Start

use vld_sqlx::prelude::*;

vld::schema! {
    #[derive(Debug)]
    pub struct NewUserSchema {
        pub name: String  => vld::string().min(1).max(100),
        pub email: String => vld::string().email(),
    }
}

#[derive(serde::Serialize)]
struct NewUser { name: String, email: String }

let user = NewUser { name: "Alice".into(), email: "alice@example.com".into() };
validate_insert::<NewUserSchema, _>(&user)?;
// now safe to insert via sqlx::query!(...)

Re-exports§

pub use vld;

Modules§

prelude

Structs§

Validated
A wrapper that proves its inner value has been validated against schema S.
VldBool
A validated boolean column type.
VldFloat
A validated float column type.
VldInt
A validated integer column type.
VldText
A validated text column type.

Enums§

VldSqlxError
Error returned by vld-sqlx operations.

Functions§

validate_insert
Validate a value against schema S before inserting.
validate_row
Validate a row loaded from the database against schema S.
validate_rows
Validate a batch of rows against schema S.
validate_update
Alias for validate_insert — same logic applies to updates.