orchid-orm: [bug] `.parse` not work for `null` value
export class TestTable extends BaseTable {
columns = this.setColumns((t) => ({
test: t.varchar().nullable().parse((input) => input ?? 'default when input is null')
})
The parse is called if test has value, but not called when test is null
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- Stop handling null in column `parse`, add `parseNull` for this instead (#405), (#96) — committed to romeerez/orchid-orm by romeerez 2 years ago
- Stop handling null in column `parse`, add `parseNull` for this instead (#405), (#96) — committed to romeerez/orchid-orm by romeerez 2 years ago
- Stop handling null in column `parse`, add `parseNull` for this instead (#405), (#96) — committed to romeerez/orchid-orm by romeerez 2 years ago
- Stop handling null in column `parse`, add `parseNull` for this instead (#405), (#96) — committed to romeerez/orchid-orm by romeerez 2 years ago
Published: now
parsecan handlenullif the column is nullable, here are the docs.To be honest as I thought more I started to think that handling nulls in parse/encode should be allowed. There are multiple scenarios when user may want to store or avoid storing nulls even if allowed by the database (such as asserting uniqueness in Postgres<15 where there is no
nulls distinct, simplifying ordering without having to deal withnulls first, automatically converting empty strings to null, etc.) Also, allowingparseto return some kind of ‘default singleton object’ or special kind ofNaN(e.g. when storing fractional numbers) is also reasonable.Now then if user wants to abuse
parseto return a default banner, so be it. 😃