drizzle-team / drizzle-team/drizzle-orm

[BUG]: Sqlite queries on columns with null values do not create a property in the returned object

Open
#2,154 0 comments 0 reactions 0 assignees View on GitHub
bug db/sqlite priority qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.29.4

### What version of `drizzle-kit` are you using?

0.20.14

### Describe the Bug

## The problem

I don't know if this is expected behavior or not, but when a column has a null value, the item property gets ignored and never gets created, in my case the time column.

![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/004a4489-f522-4758-ae2b-4130ed36bfd9)

### Table Schema
![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/8d4f526d-3fe2-4ced-bc18-efb6a7cbb3cd)

### Table values
![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/e2c9edea-b976-49fe-9e7c-8e999439a7ec)
### Drizzle schema
![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/fb5f34c3-b02d-4e1c-baa0-332932cdbb62)

### The query getting executed to get the values out

![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/9217fa6a-4ee9-42ce-bdf0-3673a9fdd107)

Running this query in a dbBrowser for sqlite returns the following

![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/c723717b-4c60-4184-9b80-b3852d795661)

The same query on a different set of images that do have a value in the time column, result in the time property being added to the object

![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/c9018ef3-a574-4fb7-9c83-a49323d64364)

### Expected behavior

### Expected Behavior

The object resulting should have the time property set to null, because otherwise this would lead to unexpected bugs like what happened to me where I had a check like this

`if (image.time !== null) {
newPlaylistImagesTimeSet.add(image.time);
}`

in this instance this evaluates to true, because undefined !== null so it lead to all sorts of headaches and an infinite loop blocking the main thread 🤣

type inference from the schema did not have a problem at all letting me do this because image.time should exist, technically even if it is null.

### What the query should return
![image](https://github.com/drizzle-team/drizzle-orm/assets/101421807/89687488-169b-4a84-8311-6cc6f93cea99)

### Final thoughts

Again, I don't know if there is something I'm missing, or if it's actually documented behavior, but I highly doubt it.

### Environment & setup

this occurs both in production and development.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.