Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Transform null back to undefined #545

Unanswered
user72356 asked this question in Q&A
Discussion options

I know it's possible to create a transform so that undefined values are changed into null values for mutative queries such as insert, update.

What I just realized is that it doesn't work the other way around! So when I issue a select query that returns null values, the resulting object contains null values instead of undefined.

How can I transform from null to undefined?

You must be logged in to vote

Replies: 1 comment

Comment options

I found a way to do this... It appears to work but additional feedback appreciated:

export const sql = postgres(
 "CONNECTION_STRING",
 {
 transform:
 {
 ...postgres.camel,
 undefined: null, 
 value:
 {
 from: value => value === null ? undefined : value
 }
 }
 });

I have a couple of questions/suggestions: could there be an option such as null: undefined to be the counterpoint to undefined: null? Additionally, why is there no to option under value? I can't see why someone would only want to transform data in one direction.

Thank you

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /