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

Most upvoted comments

Published: now parse can handle null if 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 with nulls first, automatically converting empty strings to null, etc.) Also, allowing parse to return some kind of ‘default singleton object’ or special kind of NaN (e.g. when storing fractional numbers) is also reasonable.

Now then if user wants to abuse parse to return a default banner, so be it. 😃