DT
Drizzle Team•5mo ago
psytrx

`findFirst` returns `Record<Key, undefined>` instead of `undefined` for empty result sets

Hi! For queries with no results, I'm expecting to get undefined, as the docs state. However, the return value is an object with all columns/props set to undefined. I use sqlocal as a SQLite driver. Is this something the driver could be responsible for? Any guidance on where to start looking?
2 Replies
psytrx
psytrxOP•5mo ago
Same behavior using db.select().from(table).get();. The types seem fine in both cases.
const findFirstResult = await db.query.instance.findFirst();
const selectResult = await db.select().from(clientSchema.instance).get();
console.log({ findFirstResult, selectResult });
const findFirstResult = await db.query.instance.findFirst();
const selectResult = await db.select().from(clientSchema.instance).get();
console.log({ findFirstResult, selectResult });
logs:
Object {
findFirstResult: Object { id: undefined, seed: undefined, createdAt: Invalid Date },
selectResult: Object { id: undefined, seed: undefined, createdAt: Invalid Date }
}
Object {
findFirstResult: Object { id: undefined, seed: undefined, createdAt: Invalid Date },
selectResult: Object { id: undefined, seed: undefined, createdAt: Invalid Date }
}
psytrx
psytrxOP•5mo ago
Took me a while, but I finally found another issue that validated me. https://github.com/drizzle-team/drizzle-orm/issues/3394#issuecomment-2912129233 How can I make this issue gather pace? Just suggest a PR? I can't stand having static patches in my project 😄
GitHub
[BUG]: "Cannot read properties of undefined" because empty "rows" d...
What version of drizzle-orm are you using? 0.36.0 What version of drizzle-kit are you using? 0.27.1 Describe the Bug I use Drizzle SQLite Proxy to connect and execute queries to a SQLite WASM datab...

Did you find this page helpful?