Midwess

pglite-rs embeds the postgres-pglite engine in a Rust process. The crate package is pglite-rs; the library import is pglite.

cargo add pglite-rs
use pglite::PGlite;

# async fn run() -> Result<(), pglite::Error> {
let db = PGlite::open("./data").await?;
db.exec("CREATE TABLE users (id serial PRIMARY KEY, name text)").await?;

let rows = db.query("SELECT id, name FROM users WHERE id > $1", &[&0i32]).await?;
let name: &str = rows[0].get(1)?;

db.close().await?;
# Ok(())
# }

Why use it

  • Real PostgreSQL SQL, types, MVCC, transactions, extensions, and wire-protocol rows.
  • No external server for single-process mode.
  • Runtime-neutral async API built on futures.
  • Unix socket gateway for SQLx, SeaORM, Diesel, and other Postgres clients.
  • Optional multi-process mode for concurrent sessions.
  • Optional logical-replication consumer.

Main APIs

Type Purpose
PGlite Open, query, transact, listen, copy, dump, socket URI.
PGliteOptions Username, database, durability, startup params, locale provider.
Transaction exec, query, commit, rollback; rollback on drop.
Row / Column Typed row access through postgres-types.
LiveQuery Re-run a SELECT when watched tables change.
MultiProcessOptions Child postmaster + connection pool config.
Replica / ReplicaConfig Logical-replication stream from upstream Postgres.

On this page