Cannot read properties of undefined (reading '0')
What is the expected behavior when using
get()
when there would be no matching results for a given select query? Does it return null
or would this be an error? At present it's giving an error. I'm new to discord, but I guess I expected it to return a null
. For example, the following query works and returns an empty array:
whereas changing all()
to get()
results in error trying to access first element of an empty array (drizzle-orm/utils.js:40:37
):
4 Replies
Do you know what is the behavior of the raw driver in this case?
We tried to model the execution methods in SQLite the same way they work in raw drivers
I'm using better-sqlite3. Assuming the equivalent statement is something like:
If there are no matching records, there is no error and the result will be
undefined
.
The error happens at line 34 of utils.ts:
https://github.com/drizzle-team/drizzle-orm/blob/70ff50bb7c9bd956bae8cceca937374614576c11/drizzle-orm/src/utils.ts#L34
The driver is returning undefined
for the row value (as expected), but the mapResultRow is not checking for that, and attempts the process the values anyway. Before logging a bug I thought I had better check if this is expected or not.GitHub
drizzle-orm/utils.ts at 70ff50bb7c9bd956bae8cceca937374614576c11 · ...
TypeScript ORM for SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
GitHub
[BUG]: Cannot read properties of undefined (reading '0') on get() w...
What version of drizzle-orm are you using? 0.23.2 Describe the Bug Assuming a users table... const users = sqliteTable( "users", { email: text("email").notNull() }, // ... (user...
Thanks! We'll definitely check and fix once we figure out our current stuff ðŸ«