Title: sqlite: bind parameters the same way `better-sqlite3` does. · Issue #67353 · nodejs/node · GitHub
Open Graph Title: sqlite: bind parameters the same way `better-sqlite3` does. · Issue #67353 · nodejs/node
X Title: sqlite: bind parameters the same way `better-sqlite3` does. · Issue #67353 · nodejs/node
Description: What is the problem this feature will solve? Hey 👋 Currently, node:sqlite is close to being a drop-in replacement for better-sqlite3 in query builders, ORMs and drivers, which is great, except parameters are bound differently. Integratio...
Open Graph Description: What is the problem this feature will solve? Hey 👋 Currently, node:sqlite is close to being a drop-in replacement for better-sqlite3 in query builders, ORMs and drivers, which is great, except para...
X Description: What is the problem this feature will solve? Hey 👋 Currently, node:sqlite is close to being a drop-in replacement for better-sqlite3 in query builders, ORMs and drivers, which is great, except para...
Opengraph URL: https://github.com/nodejs/node/issues/67353
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"sqlite: bind parameters the same way `better-sqlite3` does.","articleBody":"### What is the problem this feature will solve?\n\nHey 👋\n\nCurrently, `node:sqlite` is close to being a drop-in replacement for `better-sqlite3` in query builders, ORMs and drivers, which is great, except parameters are bound differently. Integrations written against `better-sqlite3` pass parameters as an array, e.g. Kysely, Knex and Prisma 7:\n\nhttps://github.com/kysely-org/kysely/blob/67263069a242600e914e8a9e03b118e8cbf4267c/src/dialect/sqlite/sqlite-driver.ts#L117\nhttps://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/dialects/better-sqlite3/index.js#L52\nhttps://github.com/prisma/prisma/blob/0b596ffecfcc55e37d6a7095c03193e2d28b8090/packages/adapter-better-sqlite3/src/better-sqlite3.ts#L90\n\n`node:sqlite` treats an array as a named parameters object, with keys `'0'`, `'1'`, etc., so none of them can accept a `node:sqlite` `Database` without changes, and wrappers have to adapt every call, e.g. MikroORM 7:\n\nhttps://github.com/mikro-orm/mikro-orm/blob/14737a2349c834dbb39e1dc82bd5adf32fb2531c/packages/sql/src/dialects/sqlite/NodeSqliteDialect.ts#L32-L33\n\n`better-sqlite3` flattens arrays into anonymous parameters, in any position, and accepts a single named parameters object in any position:\n\nhttps://github.com/WiseLibs/better-sqlite3/blob/dbc2ea1165fef1f599b9be12faea33fa5e9d7ffb/src/util/binder.cpp#L165-L186\n\n`node:sqlite` only treats the first argument as a potential named parameters object:\n\nhttps://github.com/nodejs/node/blob/18b32a3b1552e199a01f1a8d9fd64aa756d3b75b/src/node_sqlite.cc#L3859-L3860\n\n```js\nimport { Database } from 'node:sqlite'\n\nconst db = new Database(':memory:')\n\ndb.prepare('select ? as a, ? as b').all([1, 2])\n// Error: Unknown named parameter '0'\n\ndb.prepare('select ? as a, ? as b, ? as c').all(1, [2, 3])\n// Error: Provided value cannot be bound to SQLite parameter 2.\n\ndb.prepare('select :x as x, ? as a').all(2, { x: 1 })\n// Error: Provided value cannot be bound to SQLite parameter 3.\n\nconst stmt = db.prepare('select ? as a, ? as b')\nstmt.setAllowUnknownNamedParameters(true)\nstmt.all([1, 2])\n// [ { a: null, b: null } ] 😬\n```\n\n| | `better-sqlite3` | `node:sqlite` |\n|---|---|---|\n| `all(1, 2)` | ✅ | ✅ |\n| `all([1, 2])` | ✅ | ❌ `Unknown named parameter '0'` |\n| `all([1, 2], 3)` | ✅ | ❌ `Unknown named parameter '0'` |\n| `all(1, [2, 3])` | ✅ | ❌ `Provided value cannot be bound to SQLite parameter 2.` |\n| `all([1], [2, 3])` | ✅ | ❌ `Unknown named parameter '0'` |\n| `all({ x: 1 }, 2)` | ✅ | ✅ |\n| `all(2, { x: 1 })` | ✅ | ❌ `Provided value cannot be bound to SQLite parameter 3.` |\n| `all([2, 3], { x: 1 })` | ✅ | ❌ `Unknown named parameter '0'` |\n| `all({ x: 1 }, [2, 3])` | ✅ | ❌ `Provided value cannot be bound to SQLite parameter 2.` |\n\nThis was raised from a different angle (stack size) in #57932, which was closed as stale.\n\n### What is the feature you are proposing to solve the problem?\n\n`all()`, `get()`, `iterate()` and `run()` should bind parameters the same way `better-sqlite3` does: arrays are flattened into anonymous parameters, in any position, and a single plain object, in any position, is named parameters.\n\nEvery call shape this changes currently throws, or silently binds `NULL` with `setAllowUnknownNamedParameters(true)`, so no working code relies on the current behavior.\n\nTogether with #67352 (`reader`), this lets Kysely's `better-sqlite3` dialect run on a `node:sqlite` `Database` as is: migrations, `insert ... returning`, raw queries, streaming, transactions and introspection all pass with just those two differences shimmed.\n\n### What alternatives have you considered?\n\nOnly accepting an array as the first argument. It covers the most common call shape, but integrations that use the other shapes would still need changes.\n\nSpreading in userland, `statement.all(...parameters)`. It works up to SQLite's default limit of 32766 parameters, but it's exactly the downstream change we want to avoid: every `better-sqlite3`-based integration has to special-case `node:sqlite`, and switching their call sites to spread breaks wrappers that implement the array signature.\n","author":{"url":"https://github.com/igalklebanov","@type":"Person","name":"igalklebanov"},"datePublished":"2026-11-08T22:55:33Z","url":"https://github.com/nodejs/node/issues/67353"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8a6c2909-ce32-bcf0-3478-9104e5ebb568 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E52E:24645:C02F90:FD9AB6:6B01C49B |
| html-safe-nonce | f5128ce2bc368c51eb7133b08a2b9836ebe05dc086e5e8c853548243ec1221e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTJFOjI0NjQ1OkMwMkY5MDpGRDlBQjY6NkIwMUM0OUIiLCJ2aXNpdG9yX2lkIjoiMzY1NzY2MTQ0NDYxNjQ3MTcwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ec96befefd9032a28c8dc9ab4ce690b4f40fb6f6ebc9eff5e1c5fe9b23da4694 |
| hovercard-subject-tag | issue:6276646599 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/67353/issue_layout |
| twitter:image | https://opengraph.githubassets.com/44d48ed986496f8beeb07ede622c5c48e6ed2df1dcd2337a72737b2eb2b468f3/nodejs/node/issues/67353 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/44d48ed986496f8beeb07ede622c5c48e6ed2df1dcd2337a72737b2eb2b468f3/nodejs/node/issues/67353 |
| og:image:alt | What is the problem this feature will solve? Hey 👋 Currently, node:sqlite is close to being a drop-in replacement for better-sqlite3 in query builders, ORMs and drivers, which is great, except para... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | igalklebanov |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width