Hew packages

hew.db.postgres

Actor-owned PostgreSQL client with typed errors and query snapshots

Use version 0.4.1

hew add hew.db.postgres --version 0.4.1
Declared Hew requirement
>=0.6.2, <0.8.0
Licence
MIT OR Apache-2.0
Published
2026-10-22T10:01:22.040Z

Dependencies

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.