oxisql-postgres — Pure-Rust PostgreSQL backend for OxiSQL
PostgreSQL backend over the
tokio-postgreswire protocol with OxiTLS / RustCrypto TLS (nolibpq, noopenssl-sys); COPY, LISTEN/NOTIFY, pipeline batching, and extended type mapping.
Status: Stable.
What it is
oxisql-postgres provides PgConnection, which implements
oxisql_core::Connection over tokio-postgres — speaking the PostgreSQL
Frontend/Backend Protocol version 3 directly on the wire. There is no C
client library: no libpq, no libssl, no openssl-sys, and no ring. TLS
is routed entirely through OxiTLS and the rustls + rustls-rustcrypto
RustCrypto provider, so a build of this crate is 100% Pure Rust and needs no
system C toolchain or *-dev headers.
Beyond plain execute/query, the crate exposes the higher-value parts of the
PostgreSQL protocol that thin wrappers usually omit: the COPY bulk
load/unload protocol, LISTEN/NOTIFY asynchronous notifications delivered as
a Stream, pipeline batching (many statements flushed in a single network
round-trip), prepared-statement caching, and an extended type mapping that
round-trips all 13 oxisql_core::Value variants (UUID, JSONB, NUMERIC, arrays,
timestamps, …).
It is part of the OxiSQL Pure-Rust workspace and is the
backend selected when you open a postgres:// URL through the oxisql facade.
Installation
[]
= "0.1.2"
MSRV 1.89 · edition 2021 · Apache-2.0.
Quick start
use ;
use Connection;
async
TLS via OxiTLS (RustCrypto provider)
use ;
async
Two ready-made TlsMode constructors cover common cases without hand-building a
ClientConfig: TlsMode::skip_verify() (accept any server certificate — dev
only) and TlsMode::with_ca_pem(pem_bytes) (trust a custom CA from PEM). Both
default to the RustCrypto crypto provider.
Fluent builder
use ;
async
Key API
| Item | Description |
|---|---|
PgConnection::connect(conn_str, tls) |
Connect with a libpq-style key=value string or a postgres:// / postgresql:// URL (auto-detected) |
PgConnection::connect_with_timeout(conn_str, tls, dur) |
As above, wrapped in a Tokio timeout |
PgConnection::connect_skip_verify(conn_str) / connect_with_ca(conn_str, pem) |
TLS connect shortcuts |
PgConnection::from_client(client) |
Wrap an existing tokio_postgres::Client |
PgConnectionBuilder |
Fluent config: host / port / user / password / dbname / connect_timeout_secs / tls_mode (also tls_skip_verify / tls_with_ca_pem) → connect() |
TlsMode |
Disabled or Rustls(ClientConfig); constructors skip_verify(), with_ca_pem(pem) |
PgTransaction |
oxisql_core::Transaction with savepoint / release_savepoint / rollback_to_savepoint |
PgPrepared |
Caches tokio_postgres::Statement, keyed by a hash of the SQL text |
PgPipeline |
add_execute(sql, params) / add_query(sql, params) / finish() → PipelineResult — batch in one round-trip |
NotificationStream / PgNotification |
Async stream returned by listen(channel) |
ColumnDescription |
Column name + type metadata via describe(sql) (no execution) |
parse_pg_conn_str(s) → PgConnParts |
Parse a connection string / URL into its parts |
Capabilities
COPY — bulk load / unload (src/copy.rs)
# async
LISTEN / NOTIFY (src/notify.rs)
# async
Notifications are only routed on connections created via PgConnection::connect
(the background driver that dispatches NotificationResponse is spawned there);
they are not available on a from_client connection.
Pipeline batching (src/pipeline.rs)
# async
Prepared statements, describe & introspection
prepare(sql) returns a PgPrepared whose underlying Statement is cached by
SQL hash, so re-preparing the same text reuses the server-side plan.
describe(sql) returns Vec<ColumnDescription> without executing the query.
Schema introspection (tables, columns, indexes, foreign_keys) is served
from information_schema and pg_indexes.
Type mapping
All 13 oxisql_core::Value variants round-trip. Parameters are encoded with
explicit type OIDs; results can be requested in binary format (query_binary).
| PostgreSQL type | oxisql_core::Value |
|---|---|
BOOL |
Bool |
INT2 / INT4 / INT8 |
I64 |
FLOAT4 / FLOAT8 |
F64 |
TEXT / VARCHAR / BPCHAR |
Text |
BYTEA |
Blob |
TIMESTAMP / TIMESTAMPTZ |
Timestamp (µs since epoch) |
DATE |
Date (days since epoch) |
TIME |
Time (µs since midnight) |
UUID |
Uuid (u128) |
JSONB |
Json |
NUMERIC |
Decimal (string) |
ARRAY (e.g. INT[], TEXT[]) |
Array |
Test coverage
61 tests passing under cargo test (which includes doctests). In addition,
6 integration tests are live-server-gated (TLS live connect, COPY IN/OUT, and
4× LISTEN/NOTIFY). These live-server tests are marked #[ignore] because they
require a real PostgreSQL instance; the remaining #[ignore]d integration tests
(CRUD cycles, isolation, reconnect, pooling) are also gated the same way and are
skipped when no server is available. Enable them with a running server and the
integration-postgres feature.
Part of the OxiSQL workspace
This crate is one of 17 crates in the Pure-Rust OxiSQL workspace
(1,720 workspace tests pass). It is the PostgreSQL backend behind the unified
oxisql facade; see the workspace README for the embedded engine, MySQL
backend, connection pool, migrations, and DataFusion integration.
License
Apache-2.0 — Copyright © 2024–2026 COOLJAPAN OU (Team Kitasan).