SQLBraid is a SQL-first data-access toolkit for TypeScript that lets developers embed plain SQL in TypeScript while adding safe value binding, readable dynamic SQL, and explicit runtime contracts. Ordinary ${value} interpolation becomes a value bind, and structural SQL pieces use helpers like sql.ident, sql.fragment, sql.list, sql.join, sql.raw and sql.empty. Compiler-aware @braid directives (if, choose, when, otherwise, where, set, trim) produce lazy, lowered branches so inactive SQL stays inactive. The renderer yields an immutable RenderedStatement (segments.length === parameters.length + 1) and the adapter is responsible for placeholder materialization ($1, ?, :1, etc.). A Node SQLite quickstart demonstrates the ergonomics: create a DB, run SQL with sql.rows and get typed row objects.
Execution is governed by explicit result contracts and a compact runtime surface: sql.rows, sql.command, and sql.call distinguish row, command, and routine results; db.all, db.one, db.maybeOne and db.stream require sql.rows, while db.execute can accept mixed kinds and validates result kind after I/O. Standard Schema attachments validate and map one row to one application value; SQLBraid does not auto-hydrate relations or infer complex join shapes. Connection handling separates direct executors from pooled ConnectionProvider leases; db.session and db.tx acquire and reuse physical leases, nested transactions use savepoints when supported, and unsupported features fail with explicit BRAID errors. Cancellation is capability-driven via AbortSignal. The API is versioned and driver integrations are provided as modular sqlbraid/* packages; core public API reached 1.0.0.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.