Skip to content

sqlx

sqlx is a compile-time checked SQL toolkit for Rust.

Read-only transactions

sqlx doesn't have a read_only option on its transaction builder. You can use a raw query to set the session default:

main.rs
rust
sqlx::query("SET default_transaction_read_only = on")
    .execute(&readonly_pool)
    .await?;

Or use a dedicated read-only user configured in halephant:

main.rs
rust
let write_pool = PgPoolOptions::new()
    .connect("postgres://myapp:pw@halephant:6432/myapp")
    .await?;

let read_pool = PgPoolOptions::new()
    .connect("postgres://myapp_ro:pw@halephant:6432/myapp")
    .await?;

See the read replica guide for halephant configuration.