rusticx
Database Guides

PostgreSQL

Setting up and using rusticx with PostgreSQL and the postgres feature flag.

Setup

Add rusticx with the postgres feature to Cargo.toml:

[dependencies]
rusticx = { version = "0.1", features = ["postgres"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
uuid = { version = "1", features = ["v4", "serde"] }

Connection String

postgres://username:password@host:port/database

Common formats:

# Local development (no password)
postgres://localhost/mydb

# Full credentials
postgres://alice:secret@localhost:5432/production

# With SSL
postgres://alice:secret@db.example.com:5432/production?sslmode=require

Creating a Repo

use rusticx::prelude::*;

let repo = PostgresRepo::<User>::new("postgres://localhost/mydb").await?;
repo.migrate().await?;

PostgreSQL-Specific Types

rusticx maps Rust types to PostgreSQL types as follows:

Rust TypePostgreSQL Type
UuidUUID
StringVARCHAR
i32INTEGER
i64BIGINT
f32REAL
f64DOUBLE PRECISION
boolBOOLEAN
Option<T>T (nullable)

Raw SQL with PostgreSQL

Use sqlx's $1, $2 placeholder syntax for raw queries:

let rows = repo
    .adapter()
    .query_raw("SELECT id, name FROM users WHERE role = $1 AND score > $2", &[&"admin", &100])
    .await?;

Running PostgreSQL Locally

Using Docker:

docker run --name rusticx-pg \
  -e POSTGRES_USER=rusticx \
  -e POSTGRES_PASSWORD=secret \
  -e POSTGRES_DB=rusticxdb \
  -p 5432:5432 \
  -d postgres:16
export DATABASE_URL="postgres://rusticx:secret@localhost:5432/rusticxdb"

On this page