Skip to main content
Run commands from the matching source checkout. Start with SQLite for a self-contained program. Use an isolated local test database when trying a server driver; these examples create or migrate a users table.

SQLite CRUD API

Source: crates/rydantic/examples/sqlite_api.rs
Exercises a create request through the Axum router and SQLite, prints Validated HTTP -> SQLite -> JSON: OK and exits. Omit -- --smoke to serve on 127.0.0.1:3000. The CRUD tutorial walks through create, rejected input, updates, deletion and persistence.

The same API across three databases

Source: crates/rydantic/examples/database_api.rs
DATABASE_URL selects the backend; the corresponding Cargo feature supplies its driver. The smoke program inserts a temporary user through HTTP, parses the response, deletes that row and exits. Successful runs print the selected dialect and JSON: OK. Omit -- --smoke to start the server. Use LISTEN_ADDR for a different loopback address. All variants expose: Read database backends for storage representations and queries for filtering and transactions.

Upgrade a table from model changes

Source: crates/rydantic/examples/automatic_migrations.rs
Creates accounts(id, name), inserts Alice, then upgrades to a model with display_name, enabled and note. It prints the change descriptions and a migration receipt. Embedded assertions verify preserved values, defaults and a second no-op migration. The program uses its own in-memory database. The CRUD tutorial includes its full source; the migration reference covers preview/apply, destructive changes and server-database behavior.