Saori
DTDrizzle Team
•Created by Saori on 2/17/2024 in #help
Raw mysql query not accepting variable input
Example in the docs: https://orm.drizzle.team/docs/sql#sql-template
Code that works for me:
Code that fails for me:
Error message:
Sorry if this question has been asked, I tried searching but failed to find anything. Thank you
async listAllContent(rowNames: string[]) {
const result = await db.execute(sql`SELECT * FROM tracked_address`)
console.log('All content:', result)
}
async listAllContent(rowNames: string[]) {
const result = await db.execute(sql`SELECT * FROM tracked_address`)
console.log('All content:', result)
}
async listAllContent(rowNames: string[]) {
const command = 'SELECT * FROM tracked_address'
const result = await db.execute(sql`${command}`)
console.log('All content:', result)
}
async listAllContent(rowNames: string[]) {
const command = 'SELECT * FROM tracked_address'
const result = await db.execute(sql`${command}`)
console.log('All content:', result)
}
indexer:dev: throw new DatabaseError(error.message, 400, error);
indexer:dev: ^
indexer:dev:
indexer:dev: DatabaseError: syntax error at position 32 near 'SELECT * FROM tracked_address'
indexer:dev: at Connection.execute (/node_modules/.pnpm/@[email protected]/node_modules/@planetscale/database/dist/cjs/index.js:99:19)
indexer:dev: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
indexer:dev: status: 400,
indexer:dev: body: {
indexer:dev: message: "syntax error at position 32 near 'SELECT * FROM tracked_address'",
indexer:dev: code: 'UNKNOWN'
indexer:dev: }
indexer:dev: }
indexer:dev: throw new DatabaseError(error.message, 400, error);
indexer:dev: ^
indexer:dev:
indexer:dev: DatabaseError: syntax error at position 32 near 'SELECT * FROM tracked_address'
indexer:dev: at Connection.execute (/node_modules/.pnpm/@[email protected]/node_modules/@planetscale/database/dist/cjs/index.js:99:19)
indexer:dev: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
indexer:dev: status: 400,
indexer:dev: body: {
indexer:dev: message: "syntax error at position 32 near 'SELECT * FROM tracked_address'",
indexer:dev: code: 'UNKNOWN'
indexer:dev: }
indexer:dev: }
4 replies