vld-sqlx 0.6.1

SQLx integration for the vld validation library — validate before insert/update, typed column wrappers
Documentation

vld-sqlx

crates.io docs.rs

SQLx integration for vld: validate values before insert / update and after select, and bind validated column wrappers (VldText, VldInt, VldFloat, VldBool).

Install

[dependencies]
vld = "0.5"
vld-sqlx = "0.5"
sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite"] }

Features

Feature Default Effect
sqlx-0_8 yes SQLx 0.8
sqlx-0_9 SQLx 0.9 (Rust 1.94+)
sqlite yes SQLite driver
postgres / mysql Postgres / MySQL drivers

Enable exactly one of sqlx-0_8 / sqlx-0_9.

Example

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)?;
// sqlx::query("INSERT ...").bind(&user.name).bind(&user.email).execute(&pool).await?;

Documentation

MSRV: 1.85 (sqlx-0_9: 1.94), see MSRV.md.

License

MIT