-
Notifications
You must be signed in to change notification settings - Fork 835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support sql.Null #1877
Comments
I don't see why not. It should just be another sql.Scanner and driver.Valuer to pgx. |
@jackc Well, I was just about to open a similar issue . The problem, why this does not work, is that these types probably implement the Example usage would then look like this: // Nullable holds a nullable value.
type Nullable[T any] struct {
// V is the actual value when Valid.
V T
// Valid describes whether the Nullable does not hold a NULL value.
Valid bool
}
// ...
// Scan to value or not valid if nil.
func (n *Nullable[T]) Scan(src any) error {
if src == nil {
n.Valid = false
return nil
}
n.Valid = true
dst := &(n.V)
return pgx.Scan(src, dst) // <-- SEE HERE
}
// Value returns the value for satisfying the driver.Valuer interface.
func (n Nullable[T]) Value() (driver.Value, error) {
if !n.Valid {
return nil, nil
}
return pgx.Value(n.V.) // <-- SEE HERE
} Feel free to correct me, if I'm missing something :) |
@lefinal Can you provide an example usage that wouldn't work? I'm having trouble picturing it. |
@jackc For example |
A new generic Null type is landing in Go 1.22. I wanted to confirm that pgx will work with this type without any updates. Thanks!
The text was updated successfully, but these errors were encountered: