Skip to main content

Crate bsql_driver_postgres

Crate bsql_driver_postgres 

Source
Expand description

PostgreSQL wire protocol driver for bsql.

bsql-driver-postgres is a purpose-built PostgreSQL driver optimized for bsql’s architecture: binary protocol only, arena allocation for row data, pipelined extended query protocol, LIFO connection pool with fail-fast semantics.

§Design

  • Binary protocol only — numeric types are memcpy, not parsed from ASCII.
  • Arena allocation — all row data from one query shares a single bump allocator.
  • Pipelined messages — Parse+Bind+Execute+Sync in one TCP write.
  • Statement cache — keyed by rapidhash of SQL text. Second query skips Parse.
  • LIFO pool — returns the warmest connection (best PG backend cache locality).
  • Fail-fast — pool exhaustion returns an error immediately, never blocks.
  • No unsafe code#![forbid(unsafe_code)].

§Example

use bsql_driver_postgres::{Pool, Arena};

let pool = Pool::connect("postgres://user:pass@localhost/db").await?;
let mut conn = pool.acquire().await?;
let mut arena = Arena::new();

let hash = bsql_driver_postgres::hash_sql("SELECT $1::int4 + $2::int4 AS sum");
let result = conn.query(
    "SELECT $1::int4 + $2::int4 AS sum",
    hash,
    &[&1i32, &2i32],
    &mut arena,
).await?;

let row = result.row(0, &arena);
assert_eq!(row.get_i32(0), Some(3));

Re-exports§

pub use codec::Encode;
pub use pool::Pool;
pub use pool::PoolBuilder;
pub use pool::PoolGuard;
pub use pool::PoolStatus;
pub use pool::Transaction;

Modules§

arena
Re-export from bsql-arena — the arena is a shared crate used by all drivers.
codec
Binary encode/decode for PostgreSQL types.
pool
Connection pool — LIFO ordering, fail-fast acquire, no timeouts.

Structs§

Arena
A bump allocator for row data.
ColumnDesc
Description of a result column.
Config
Connection configuration parsed from a URL.
Connection
A PostgreSQL connection with statement cache and inline message processing.
Notification
A notification received during normal query processing.
PgDataRow
A temporary view of a single PostgreSQL DataRow message.
PrepareResult
Result of a prepare_describe call — column and parameter metadata without executing the query.
QueryResult
Result of a query execution. Owns the row offset metadata.
Row
A view into a single result row, borrowing data from the arena.
SyncConnection
A synchronous PostgreSQL connection over a Unix domain socket.

Enums§

DriverError
Error type for all bsql-driver-postgres operations.
SslMode
SSL/TLS connection mode.

Functions§

hash_sql
Compute a rapidhash of a SQL string.

Type Aliases§

SimpleRow
A single row of text values returned by simple_query_rows.