Use MaybeNullableValue in other postgres function #4241
guissalustiano
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Got catch. I would say the correct solution is to use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In postgres
to_json
function @weiznich comes with amagicMaybeNullableValue
implementation (he provides an explanation here)This trait allows "overload" the
to_json
function to work asto_json(e: SqlType) -> Json
to_json(e: Nullable<SqlType>) -> Nullable<Json>
Which makes their use much cleaner, without the need to call
assume_not_nullable()
and just trust in the type system.There are multiple other functions with this same behavior listed below: if you pass null, Postgres returns null, if you don't pass null it will never return not null
Would it be possible to generalize the
MaybeNullableValue
so we can use it in the other cases? Or would it be better to make a helper type for each one?Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions