Syntax Error

Error:
DatabaseError: syntax error at position 92 near 'where'
at Connection.execute (file:///F:/MELONLY/cron/node_modules/@planetscale/database/dist/index.js:78:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async updateShift (file:///F:/MELONLY/cron/dist/database.js:202:5)
at async endShift (file:///F:/MELONLY/cron/dist/crons/erlc-shifts-end.js:61:5)
at async default (file:///F:/MELONLY/cron/dist/crons/erlc-shifts-end.js:46:36)
at async CJ.<anonymous> (file:///F:/MELONLY/cron/dist/index.js:22:25) {
status: 400,
body: {
message: "syntax error at position 92 near 'where'",
code: 'UNKNOWN'
}
}
DatabaseError: syntax error at position 92 near 'where'
at Connection.execute (file:///F:/MELONLY/cron/node_modules/@planetscale/database/dist/index.js:78:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async updateShift (file:///F:/MELONLY/cron/dist/database.js:202:5)
at async endShift (file:///F:/MELONLY/cron/dist/crons/erlc-shifts-end.js:61:5)
at async default (file:///F:/MELONLY/cron/dist/crons/erlc-shifts-end.js:46:36)
at async CJ.<anonymous> (file:///F:/MELONLY/cron/dist/index.js:22:25) {
status: 400,
body: {
message: "syntax error at position 92 near 'where'",
code: 'UNKNOWN'
}
}
Code:
export const updateShift = async (shiftId: string, data: Partial<Shift>) => {
await db.update(shifts).set(data).where(eq(shifts.id, shiftId))
};
export const updateShift = async (shiftId: string, data: Partial<Shift>) => {
await db.update(shifts).set(data).where(eq(shifts.id, shiftId))
};
7 Replies
0xRaptor
0xRaptor10mo ago
Really confused what the syntax error actually is
Angelelz
Angelelz10mo ago
Syntax error is occurring in the query Do this to debug:
export const updateShift = async (shiftId: string, data: Partial<Shift>) => {
const query = db.update(shifts).set(data).where(eq(shifts.id, shiftId));
console.log(query.toSQL());
await query;
};
export const updateShift = async (shiftId: string, data: Partial<Shift>) => {
const query = db.update(shifts).set(data).where(eq(shifts.id, shiftId));
console.log(query.toSQL());
await query;
};
Just to see that is the query and where is the error
0xRaptor
0xRaptor10mo ago
I think I see the problem, the partial data has one value as undefined which isnt coming through in the query params So there is no passed paramater for id
Angelelz
Angelelz10mo ago
This shouldn't happen What version are you using? Drizzle should filter out undefined values
0xRaptor
0xRaptor10mo ago
0.23.13
Angelelz
Angelelz10mo ago
Yeah, that's probably why Latest version is 29.2 I believe If you update that error will go away, as drizzle now filter undefines for you
0xRaptor
0xRaptor10mo ago
Ok thanks for letting me know
Want results from more Discord servers?
Add your server