vld-diesel
Diesel integration for the vld validation library.
Validate data before inserting into the database. Provides:
| Feature | Description |
|---|---|
validate_insert::<Schema, _>(&value) |
Standalone validation before INSERT |
validate_update::<Schema, _>(&value) |
Standalone validation before UPDATE |
validate_row::<Schema, _>(&row) |
Validate data loaded from DB |
Validated<Schema, T> |
Wrapper that guarantees T passes Schema |
VldText<S> |
Validated String column type with Diesel ToSql/FromSql |
VldInt<S> |
Validated i64 column type with Diesel ToSql/FromSql |
Installation
[]
= "0.1"
= { = "0.1", = ["serialize"] }
= { = "2", = ["sqlite"] }
Backend features
| Feature | Backend |
|---|---|
sqlite (default) |
SQLite |
postgres |
PostgreSQL |
mysql |
MySQL |
Quick start
1. Validate before insert
use *;
schema!
// Validate
let user = NewUser ;
?;
// Then insert
insert_into.values.execute?;
2. Validated wrapper
let user = NewUser ;
let validated = new?;
// The inner value is guaranteed valid
insert_into
.values
.execute?;
3. Typed columns
use VldText;
schema!
// Validates on construction
let email = new?;
// Use in Diesel models — implements ToSql/FromSql for Text
4. Validate rows from DB
let users: = table.load?;
for user in &users
Running the example
License
MIT