hew.db.postgres
Actor-owned PostgreSQL client with typed errors and query snapshots
Use version 0.7.0-rc1
hew add hew.db.postgres --version 0.7.0-rc1
- Declared Hew requirement
- >=0.10.0, <0.11.0
- Licence
- MIT OR Apache-2.0
- Published
- 2026-10-26T17:16:48.938Z
Dependencies
- hew.db.sql 0.7.0-rc1
Package README
# hew.db.postgres
`hew.db.postgres` owns each PostgreSQL connection in an actor. Operations
fail with a typed `PostgresError`, which a call reports as
`.Err(.Failed(error))`; query replies are immutable wire-safe snapshots,
and SQL `NULL` is represented by `CellValue.Null`. `QueryResult`, `Row` and
`CellValue` come from [`hew.db.sql`](../sql/README.md), shared with SQLite and
MySQL.
The package wraps the native Rust `postgres` crate over a C ABI: cell values
cross that boundary as UTF-8 `bytes` text snapshots, not typed columns.
```hew
import hew.db.postgres;
import std.encoding.utf8;
fn main() {
let db = spawn postgres.Conn { connstr: "host=127.0.0.1 user=hew password=hew dbname=hew_test" };
match db.query("SELECT 41::bigint AS value") {
.Ok(query) => match query.rows[0].values[0] {
.Text(value) => println(utf8.decode_lossy(value)),
.Null => println("value is NULL"),
}
.Err(.Failed(error)) => println(postgres.error_message(error)),
.Err(_) => println("PostgreSQL actor stopped before replying"),
}
stop(db);
stopped(db);
}
```
The checked example lives at [`examples/basic.hew`](examples/basic.hew). With
PostgreSQL listening locally and the `hew_test` database/user configured, run it
from the ecosystem checkout:
```sh
hew run --pkg-path . db/postgres/examples/basic.hew
```
Parameterized methods accept `Vec<Param>` from `hew.db.sql`. For example,
`[Param.Int(42), Param.Text("First line\nSecond line"), Param.Null]` binds three
values. Use `Param.Bytes(data)` for arbitrary binary data, including invalid
UTF-8. Empty values and NULL stay distinct. See [typed SQL parameters](../sql/README.md)
for all six variants and database-specific conversions. Cell payloads remain
`bytes`, preserving exact values. SQL strings cross the native boundary with
explicit lengths.