sqlite: bind parameters the same way `better-sqlite3` does.
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 功能
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, sqlite
研究方向
Start by reading the parameter binding logic in src/node_sqlite.cc, especially the call path that currently treats only the first argument as a named parameter object. Compare its behavior with the documented call shapes and add coverage for all(), get(), iterate() and run(). Done means arrays and a single plain object bind as described in the issue, with tests confirming each listed call shape.
由索引模型根據 Issue 內容生成。
描述
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. Integrations written against better-sqlite3 pass parameters as an array, e.g. Kysely, Knex and Prisma 7:
https://github.com/kysely-org/kysely/blob/67263069a242600e914e8a9e03b118e8cbf4267c/src/dialect/sqlite/sqlite-driver.ts#L117
https://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/dialects/better-sqlite3/index.js#L52
https://github.com/prisma/prisma/blob/0b596ffecfcc55e37d6a7095c03193e2d28b8090/packages/adapter-better-sqlite3/src/better-sqlite3.ts#L90
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:
better-sqlite3 flattens arrays into anonymous parameters, in any position, and accepts a single named parameters object in any position:
node:sqlite only treats the first argument as a potential named parameters object:
import { Database } from 'node:sqlite'
const db = new Database(':memory:')
db.prepare('select ? as a, ? as b').all([1, 2])
// Error: Unknown named parameter '0'
db.prepare('select ? as a, ? as b, ? as c').all(1, [2, 3])
// Error: Provided value cannot be bound to SQLite parameter 2.
db.prepare('select :x as x, ? as a').all(2, { x: 1 })
// Error: Provided value cannot be bound to SQLite parameter 3.
const stmt = db.prepare('select ? as a, ? as b')
stmt.setAllowUnknownNamedParameters(true)
stmt.all([1, 2])
// [ { a: null, b: null } ] 😬
better-sqlite3 |
node:sqlite |
|
|---|---|---|
all(1, 2) |
✅ | ✅ |
all([1, 2]) |
✅ | ❌ Unknown named parameter '0' |
all([1, 2], 3) |
✅ | ❌ Unknown named parameter '0' |
all(1, [2, 3]) |
✅ | ❌ Provided value cannot be bound to SQLite parameter 2. |
all([1], [2, 3]) |
✅ | ❌ Unknown named parameter '0' |
all({ x: 1 }, 2) |
✅ | ✅ |
all(2, { x: 1 }) |
✅ | ❌ Provided value cannot be bound to SQLite parameter 3. |
all([2, 3], { x: 1 }) |
✅ | ❌ Unknown named parameter '0' |
all({ x: 1 }, [2, 3]) |
✅ | ❌ Provided value cannot be bound to SQLite parameter 2. |
This was raised from a different angle (stack size) in #57932, which was closed as stale.
What is the feature you are proposing to solve the problem?
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.
Every call shape this changes currently throws, or silently binds NULL with setAllowUnknownNamedParameters(true), so no working code relies on the current behavior.
Together 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.
What alternatives have you considered?
Only 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.
Spreading 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.
- 主要語言
- JavaScript
- 星號
- 124k
- 分支
- 38k
- 平均合併
- 4 天 2 小時
- 30 天內合併 PR
- 266
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 69/100
維護者通常 1 天內回覆
-
fs: document readStream.start and readStream.end可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
doc: document the Buffer.prototype.*Slice() methods可能已有人在做 @AyushCipher 今天認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 1 天內回覆
-
`styleText` fast path bypasses `options` and `options.validateStream` validation可能已有人在做 @GBra-4-669 於 8 天前認領。 未關閉util
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
riscv64
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
bug triage needed
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 2 天內回覆
-
resource-submission validation-passed
難度 1/5 1 小時以內 新手友好度 82/100
hesreallyhim/awesome-claude-code#3773 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the status可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆