Repository navigation
sqlite: statement.setReadNullAsUndefined() #59457
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
on Aug 12, 2025 When does getting null instead of undefined matter?
Honestly, this would be a good feature and I've run into a couple of cases where I have to convert SQL null types by hand. I've opened a pull request with the change: #59462.
If it gets approved there could be a database-wide option after. But this one only implements setReadNullAsUndefined() on statements.
When does getting null instead of undefined matter?
Most notably, whenever we serialize the data to store or send. In JSON, every
nullconsumes space, increases parsing time, reduces readability.Web API, especially having databases with sparse columns, usually should prefer not sending
nulls to avoid wasting traffic.Also this is semantically more correct behaviour when we expect business logic to add new columns that are sparse by design and should not affect previously inserted rows.
hasDiscountOnApril2010Promo,bonusAttackDuring1252Event,isAiGenerated,showSpecialWarningPopup,extraParams, and other stuff that inevitably happens someday.Is there any use case for this? In which situation does an
undefinedbehave in a way that, withnull, it would be a problem?I was looking into other players, and it's just a
null.Is there any use case for this? In which situation does an
undefinedbehave in a way that, withnull, it would be a problem?Besides the use cases we've laid out in this issue and the PR discussion, here are some more sources:
Drizzle ORM request for distinct
nullandundefinedhandling: drizzle-team/drizzle-orm#2745
Another for Supabase: supabase/supabase-js#244
MongoDB distinction between the types and their use cases: https://www.mongodb.com/docs/manual/reference/bson-types/migrate-undefined/Is there any use case for this? In which situation does an
undefinedbehave in a way that, withnull, it would be a problem?Besides the use cases we've laid out in this issue and the PR discussion, here are some more sources:
Drizzle ORM request for distinct
nullandundefinedhandling: drizzle-team/drizzle-orm#2745 Another for Supabase: supabase/supabase-js#244 MongoDB distinction between the types and their use cases: https://www.mongodb.com/docs/manual/reference/bson-types/migrate-undefined/Thank you for the references.
What I saw from these links is people complaining about typing (where they'd like to use something like
myprop?: string). The MongoDB link is about a migration fromundefinedtonull.The players I brought are more similar to what
node:sqliteis.Would you have an opinion here @cjihrig @nodejs/sqlite ?
Would you have an opinion here
Are any other libraries actually implementing something like this? I think it's good to differentiate between feature requests and actual implementations.
That said, I'm not opposed to this as long as it doesn't break anything. I also think it's worth benchmarking since
SQLITE_VALUE_TO_JS()is likely a pretty hot path, and taking a performance hit there wouldn't be a good idea for a feature that no other libraries ship.Reacted by Edy SilvaPeople really seem passionate about wanting
undefinedto be returned instead ofnull. I can see the appeal if you want to serialize to JSON.Interesting idea. API seems consistent. Not very complex to implement. Why not!
I consider applications should use pattern like DTO to return data to external services / users.
It's a good practice to avoid returning unwanted or sensible data. Also decoupling raw data from data-source to data-view allow easy switch from one data-source to another one, explicit interface for aggregation and so on.I think a low level API like
node:sqliteshould not have the responsibility to transform data. This kind of transformation should be done at higher level like ORM layer or Data view layer.Reacted by Edy Silva, humarkx and Miguel Marcondes Filho@LiviaMedeiros @cjihrig I’ve put together a draft PR that adds statement-level support for reading SQL NULL values as undefined.
If you’re happy with the approach, I’m happy to continue and add the relevant tests.
Reacted by Edy SilvaIs there any use case for this? In which situation does an
undefinedbehave in a way that, withnull, it would be a problem?I was looking into other players, and it's just a
null.Bun has the same behavior: https://bun.com/docs/runtime/sqlite
Note that after db.prepare(sql, options) was added these options like
readNullAsUndefinedshould be added todb.prepare(sql, options)and new DatabaseSync(path, options) as thestatement.set*functions may be deprecated.I see 2 PR's open for this issue but neither have correctly added the options: #61472 #59462
- added a commit that references this issue
on Feb 21, 2026 github-actions commented
on Jul 20, 2026 on Jul 20, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jul 20, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsAwaiting Triage
What is the problem this feature will solve?
In JS, we have two different oddballs
nullandundefined. In SQL, they are represented asNULL.Inserting them to database makes them coerced to
NULL; however selecting to JS realm always producesnulls, which is not always desirable.What is the feature you are proposing to solve the problem?
Similarly to
statement.setReadBigInts(enabled), we can havestatement.setReadNullAsUndefined()to make reads returnNULLs asundefinedinstead ofnull.Also we can have database-wide
readNullAsUndefinedoption innew DatabaseSync(path[, options])What alternatives have you considered?
Drowning in boilerplate code.