RAISEInternal error in D1 storage caused object to be reset.
✘ [ERROR] near "limit": syntax error at offset 40: SQLITE_ERRORnpx wrangler d1 export db-name --remote --output ./database.sql
limit and it's now working after I rename the table
/**
* Update milestone by milestoneId
* @param request
* @param env
* @returns
*/
const updateMilestone = async (request: Request, env: any) => {
try {
const params = new URL(request.url).searchParams
const milestoneId = parseInt(params.get('milestoneId') || '')
const milestoneData: any = await request.json()
const fields: string[] = []
const values: any[] = []
let index = 1
for (const [key, value] of Object.entries(milestoneData)) {
if (value !== undefined) {
fields.push(`${key} = ?${index}`)
values.push(value)
index++
}
}
if (fields.length === 0) {
return new Response(JSON.stringify({ error: 'No fields to update' }), { status: 400 })
}
values.push(milestoneId)
const query = `UPDATE milestone SET ${fields.join(', ')}, updatedAt = CURRENT_TIMESTAMP WHERE _id = ?${index}`
const { success } = await env.DB.prepare(query)
.bind(...values)
.run()
return new Response(JSON.stringify({ success }), { status: 200 })
} catch (err: any) {
return new Response(JSON.stringify(err), { status: 500 })
}
}limit