In my code, I update the record in the database using drizzle-orm, but for some reason the database is not updated and returns the old value.
export async function updateDailyWord(data: number) {
const date = new Date(Date.now());
console.log("new wordId: ", data);
await db.update(dailyWord)
.set({
wordId: data,
date: `${date.getFullYear()}-
${date.getMonth() + 1}-
${date.getDate()}`})
.where(eq(dailyWord.id, 1))
const updatedRecord = await db.select()
.from(dailyWord)
.where(eq(dailyWord.id, 1));
console.log("Updated record: ", updatedRecord);
}
Cmd log:
new wordId: 2
Updated record: [ { id: 1, wordId: 3, date: '2024-7-8' } ]
wordId should be 2 instead of 3.
P.S. I know about the returning method, but I don’t use it here for better logging.
I will be glad of any help.
I tried to change the set and where statement, but it didn’t help. It is worth noting that I have other functions that work with the db and they work properly, the problem is solely in updating the db.
nosebleeded is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.