{"metadata":{"name":"hew/db/sql","vers":"0.7.0","description":"Typed SQL parameters and query results shared by SQLite, MySQL and PostgreSQL","license":"MIT OR Apache-2.0","authors":["Hew Contributors"],"deps":[],"features":{},"edition":"2026","hew":">=0.10.0, <0.12.0","keywords":["database","sql"],"repository":"https://github.com/hew-lang/ecosystem","readme":"# hew.db.sql\n\n`hew.db.sql` holds the types SQLite, MySQL and PostgreSQL share: `Param` for\nquery parameters, and `QueryResult`, `Row` and `CellValue` for replies. Because\nevery driver replies with the same `QueryResult`, one function handles results\nfrom any of them:\n\n```hew\nimport std.encoding.utf8;\n\nimport hew.db.sql.{Param, CellValue, Row, QueryResult};\n\n// One line per row, columns separated by ` | `, SQL NULL shown as `NULL` and\n// an empty value shown as `''` so the two cannot be confused.\nfn render(result: QueryResult) -> string {\n    var out = result.columns.join(\" | \");\n    for row in result.rows {\n        var cells: Vec<string> = Vec.new();\n        for value in row.values {\n            match value {\n                .Null => cells.push(\"NULL\"),\n                .Text(text) => {\n                    if text.len() == 0 {\n                        cells.push(\"''\");\n                    } else {\n                        cells.push(utf8.decode_lossy(text));\n                    }\n                }\n            }\n        }\n        out = out + \"\\n\" + cells.join(\" | \");\n    }\n    out\n}\n\n// The reply a driver gives for `SELECT id, name, note FROM people WHERE id IN\n// (?, ?)` with the parameters in `main`.\nfn people() -> QueryResult {\n    let ada = Row { values: [CellValue.Text(\"1\".to_bytes()), CellValue.Text(\"Ada\".to_bytes()), CellValue.Null] };\n    let grace = Row { values: [CellValue.Text(\"2\".to_bytes()), CellValue.Text(\"Grace\".to_bytes()), CellValue.Text(bytes.new())] };\n    QueryResult { columns: [\"id\", \"name\", \"note\"], rows: [ada, grace] }\n}\n\nfn main() {\n    let params = [Param.Int(1), Param.Int(2)];\n    println(f\"bound {params.len()} parameters\");\n    println(render(people()));\n}\n```\n\nThe same program is [`examples/render_rows.hew`](examples/render_rows.hew); run\nit from the ecosystem checkout with `hew run db/sql/examples/render_rows.hew`.\n\n## Parameters\n\n```hew\nimport hew.db.sql.{Param};\n\nlet params = [Param.Int(42), Param.Text(\"First line\\nSecond line\"), Param.Null];\n```\n\nUse `Null`, `Bool(bool)`, `Int(i64)`, `Float(f64)`, `Text(string)` or\n`Bytes(bytes)` in `Vec<Param>`. Empty text, empty binary data and SQL NULL are\ndistinct values. Binary data need not be UTF-8. Parameters are bound separately\nfrom SQL, never interpolated into it.\n\nUse `?` placeholders with SQLite and MySQL, and `$1`, `$2`, etc. with\nPostgreSQL. PostgreSQL binds integers as `bigint`, floats as `double precision`,\ntext as `text` and binary data as `bytea`. The database applies explicit casts\nand column conversions; incompatible values and out-of-range conversions return\na query error. An untyped NULL needs enough SQL context to infer its type (for\nexample, `CAST($1 AS text)`). SQLite stores booleans as 0 or 1; MySQL follows its\nboolean alias for a small integer.\n\n## Query results\n\nEvery driver's `query` and `query_params` reply with the same `QueryResult`:\n\n- `QueryResult { columns: Vec<string>; rows: Vec<Row>; }`\n- `Row { values: Vec<CellValue>; }`, one value per column\n- `CellValue` — `.Null` for SQL NULL, or `.Text(bytes)` with the database's\n  text form of the value, which need not be UTF-8\n\nThe clients encode parameters using Hew's shared wire codec. The binary format\nis an internal native boundary, not an application serialization API.\n"},"version":{"name":"hew/db/sql","vers":"0.7.0","deps":[],"features":{},"cksum":"sha256:fe0cc58eb3b7ae4b35e55984c294909f2e85cd036f59c0dcaabf17f7c3b8c68c","sig":"ed25519:a20f00c9d34c6a08b62f0272f3332dca455651eb62d39f449e07b8234cb9229c6c97d2d303cb979e4f12d5cd212e6ea10db705cc56d7441ffc96c99ba29ee601","key_fp":"SHA256:QDgYk38yt+UbTDqWpi+aVd+Vkirhyd7m4y+5bVuNIpg","yanked":false,"edition":"2026","hew":">=0.10.0, <0.12.0","registry_sig":"ed25519:3fdd5088bb22a906840822929dc6e7ef5e7c8fc053f41f1df727b38609b56d031af8283a7eda2d0a89b51ba8f4088287c2465bdcd4e44e2ec9cb280b500ed20e","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-11-13T06:01:11.128Z","dl":"https://cdn.hewpkg.com/tarballs/hew/db/sql/0.7.0.tar.zst"}}