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")?;
let mut conn = pool.acquire()?;
let 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],
)?;

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, Condvar-based waiting.

Structs§

Arena
A bump allocator for row data.
ColumnDesc
Description of a result column.
Config
Implements Drop to zeroize the password field, minimizing the window where plaintext credentials live in memory.
Connection
A PostgreSQL connection over TCP, TLS, or Unix domain socket.
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
Collected result of a query: all rows’ column offsets plus metadata.
Row
A view into a single result row, borrowing data from the arena.

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.
release_resp_buf
Return a response buffer to the thread-local pool for reuse.

Type Aliases§

SimpleRow
A single row of text values returned by simple_query_rows.