
Rust and PostgreSQL JSONB Columns Done Right With Serde
Store and query JSON in PostgreSQL JSONB from Rust: sqlx Json<T> typed columns, containment and path operators, partial updates, GIN indexes and when a column beats JSON.
Talking to Postgres, MySQL and SQLite from Rust with SQLx and Diesel, and schemas that age well.

Store and query JSON in PostgreSQL JSONB from Rust: sqlx Json<T> typed columns, containment and path operators, partial updates, GIN indexes and when a column beats JSON.

Turn a PostgreSQL unique violation into a friendly conflict instead of a 500. Check is_unique_violation on the database error, read the constraint name and map foreign key errors too.

Build WHERE clauses from optional filters with QueryBuilder and push_bind, so values stay parameters and the SQL stays safe. Includes lists with IN and sorting by allowed columns.

Map rows to your own structs with query_as and the FromRow derive, or with the query_as! macro. Learn column renames, Option for nulls and the differences between the forms.

Wire Axum 0.8 and SQLx 0.9 into a typed database layer: a pool in state, a db module of compile-time checked queries, one error type, a transaction, offline builds and tests on throwaway databases.

Group statements so they succeed or fail together with pool.begin. Learn commit, the automatic rollback on drop, error handling with the question mark and lock behavior.

A pool that is too small queues requests and one that is too large exhausts the database. Learn how to size it from your server's limits, set timeouts and spot the symptoms.

Build SQLx code without a database by saving query metadata in .sqlx with cargo sqlx prepare. Includes the CI check that keeps it fresh and the errors when it is stale.

Version your schema with sqlx migrate: create files, run them at startup or in CI, embed them in the binary and handle the checksum error when a file changes.

A guide to SQLx: async queries without an ORM, compile-time checked SQL, pools, migrations, transactions and the choices around them.
We send one email when a new post is published. No spam.