Extremely weird behaviour

Apologies for the lack of better title. I have come across a weird behaviour where select().from(tablename) returns old and stale data. import { db } from "@/db/drizzle"; updateCompany({ name: "NAME 1", companyId: 50 }) updateCompany({ name: "NAME 2", companyId: 51 }) updateCompany({ name: "NAME 3", companyId: 52 }) const companies = await db.select().from(companiesTable); console.log("companies are:", companies); updateCompany code: import { db } from "@/db/drizzle"; export async function updateCompany(data: any) { const companyData = { ...data, updatedAt: new Date(), }; const company = await db .update(companiesTable) .set(companyData) .where(eq(companiesTable.companyId, data.companyId)) .returning(); return company[0]; } You'd expect that returned companies to be NAME 1,..., NAME 3 but I'm getting the old values no matter what I do. The new values are reflected in the database when I check through drizzle-studio and I check NEON db table which means my updateCompany is working but the returned value is incorrect. I ran out of ideas to troubleshoot. What could I be doing wrong? And what can I do to troubleshoot this further?
7 Replies
Mozzy
Mozzy4w ago
You are not awaiting updateCompany()
CaptainFantastic
CaptainFantasticOP4w ago
Yep I just noticed and I did that but it doesn't solve the issue
Mozzy
Mozzy4w ago
How does your code look now with the awaits?
CaptainFantastic
CaptainFantasticOP4w ago
await updateCompany({ name: "TATATAT 1", companyId: 50 }) await updateCompany({ name: "TATATAT 2", companyId: 51 }) await updateCompany({ name: "TATATAT 3", companyId: 52 }) const companies = await db.select().from(companiesTable); console.log("companies are:", companies); The console outputs oldest data
Mozzy
Mozzy4w ago
Huh, what if you do it all in a transaction?
CaptainFantastic
CaptainFantasticOP4w ago
No that's not the issue. If I run updateCompany the first time and then comment it and run companies, it still output old data while the db has the new values in It's extremely weird
Mozzy
Mozzy4w ago
Sounds like cache tbh
Want results from more Discord servers?
Add your server