Skip to content

TraversedJSONPathBuilder and undefined results #1895

Description

@sbossarte

When using the TraversedJSONPathBuilder, I often find myself needing to strip undefined from the resulting type, which $notNull is not sufficient for, and $castTo ends up being verbose. For example:

db.selectFrom('elements')
	.select(eb => [
		'id',
		eb.ref('data', '->$')
			.key('flags')
			.$castTo<Exclude<ElementData['flags'], undefined>>()
			.as('flags'),
	])
	.where(eb => eb(eb.ref('data', '->$').key('flags'), 'is not', null))

With this, I was wondering if perhaps the type returned by TraversedJSONPathBuilder should use null instead of undefined since the database doesn't actually returned undefined in these cases, does it? Or if it does, then a $notUndefined may be more appropriate?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions