{"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-rc2","deps":[],"features":{},"cksum":"sha256:837ebbfeba6945c5cb58742935e7aa127bb18ce33d03d683c118afd8accce18d","sig":"ed25519:6a48ca372cbfbe503344ed4b8f633b7854a2dac38d8ff857056752eec040fd43a51f59c35e1a106be66ebaf02e1693e6525db4d538989538b4d642f2320ebc0a","key_fp":"SHA256:sFX33aRocZfvHKm7NmU4zQHnCoCP32v1uTkJhbVQAWM","yanked":false,"edition":"2026","hew":">=0.10.0, <0.12.0","registry_sig":"ed25519:1c666e04647a60e4f4bcf11b1f3f89b46a27327a04e461f7bef00da4543810a73df4e19e176f22d9f9d5c1515d834c7432142d3871a516c7ebce5be40834c801","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-11-11T11:34:52.315Z","dl":"https://cdn.hewpkg.com/tarballs/hew/db/sql/0.7.0-rc2.tar.zst"}}