hew.db.mysql
Actor-owned MySQL client with typed errors and query snapshots
Use version 0.7.2
hew add hew.db.mysql --version 0.7.2
- Declared Hew requirement
- >=0.10.0, <0.12.0
- Licence
- MIT OR Apache-2.0
- Published
- 2026-11-21T21:55:16.510Z
Dependencies
- hew.db.sql 0.7.0
Package README
# hew.db.mysql
`hew.db.mysql` owns each MySQL connection in an actor. Operations fail with a
typed `MysqlError`, which a call reports as `.Err(.Failed(error))`; query
replies are immutable wire-safe snapshots, and SQL `NULL` is represented by `CellValue.Null` rather than an empty-string sentinel.
`QueryResult`, `Row` and `CellValue` come from [`hew.db.sql`](../sql/README.md),
shared with SQLite and PostgreSQL.
```hew
import hew.db.mysql;
import std.encoding.utf8;
fn main() {
let db = spawn mysql.Conn { url: "mysql://hew:hew@127.0.0.1:3306/hew_test" };
match db.query("SELECT 41 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(mysql.error_message(error)),
.Err(_) => println("MySQL actor stopped before replying"),
}
stop(db);
stopped(db);
}
```
The checked example lives at [`examples/basic.hew`](examples/basic.hew). With
MySQL listening locally and the `hew_test` database/user configured, run it from
the ecosystem checkout:
```sh
hew run --pkg-path . db/mysql/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.