You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code works well without template string:
const{ rows }=awaitdb.sql`SELECT * FROM bilibili_like`
The following code throws error without template string:
consttableName='bilibili_like'const{ rows }=awaitdb.sql`SELECT * FROM ${tableName}`
Error:
[nitro] [unhandledRejection] SqliteError: near "?": syntax error
at Database.prepare (/root/code/nitro-app/node_modules/.pnpm/better-sqlite3@9.6.0/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)
at Object.prepare (file:///root/code/nitro-app/node_modules/.pnpm/db0@0.1.4_better-sqlite3@9.6.0/node_modules/db0/connectors/better-sqlite3.mjs:24:29)
at Object.sql (file:///root/code/nitro-app/node_modules/.pnpm/db0@0.1.4_better-sqlite3@9.6.0/node_modules/db0/dist/index.mjs:34:38)
at Object.run (file:///root/code/nitro-app/.nitro/dev/index.mjs:928:17)
at runTask (file:///root/code/nitro-app/.nitro/dev/index.mjs:610:36) {
code: 'SQLITE_ERROR'
}
Describe the bug
sql method throw error with template string
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered:
@gyhyfj please use staticParameters while using template literals in sql queries.
TLDR; fix like this:
consttableName='bilibili_like'const{ rows }=awaitdb.sql`SELECT * FROM {${tableName}}`
Explanation: when you use template literals, db0 automatically converts them to prepared statements and tableNames are not allowed to be part of prepared statements.
Environment
node 20.12.1
nitropack 2.9.6
better-sqlite3 9.6.0
Reproduction
Error:
Describe the bug
sql
method throw error with template stringAdditional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: