You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is, Go cannot automatically Decode into an object that uses the sql nullable variables. The modern approach is to use pointers, which can be nullable.
To Reproduce
In the below example, I have copied (a) the generated struct using supabase cli, (b) a sample response from a supabase rest call, and (c) the standard approach to decoding into a go object. As you can see, the error returns:
json: cannot unmarshal string into Go struct field PublicUsersSelect.date_of_birth of type sql.NullString
package main
import (
"database/sql""encoding/json""log""strings"
)
// generated by supabase; copied here for demotypePublicUsersSelectstruct {
ActiveOrganizationId sql.NullString`json:"active_organization_id"`Avatar sql.NullString`json:"avatar"`DateOfBirth sql.NullString`json:"date_of_birth"`FirstNamestring`json:"first_name"`FullNamestring`json:"full_name"`Idstring`json:"id"`IsSetupbool`json:"is_setup"`LastNamestring`json:"last_name"`
}
funcmain() {
// usually from api; hard-coded here for demores:=`{"id":"35527ac4-dfd0-4743-89ab-a3ea226e4466","first_name":"Nicholas","last_name":"Barrow","full_name":"Nicholas Barrow","date_of_birth":"2002-02-11","avatar":null,"active_organization_id":"c7b65312-45b9-4076-a8c5-f9054fef435c","is_setup":true}`varuserPublicUsersSelecterr:=json.NewDecoder(strings.NewReader(res)).Decode(&user)
iferr!=nil {
log.Println(err)
}
}
Expected behavior
The modern approach is to use pointers, which can be nullable. Another approach is to use custom wrappers with initializers, but this seems more cumbersome.
The text was updated successfully, but these errors were encountered:
I just tested this using a quick replacement script (i.e., by just replacing all the values exactly as this #898 would) and it works perfectly, including with type-safety.
Edit: here is the script I used, to test, if you want to try:
Bug report
Describe the bug
These lines define the nullable types:
https://github.com/supabase/postgres-meta/blob/b85bf01fe51789588b87b4552d593b5510632bf9/src/server/templates/go.ts#L277C1-L288C2
The problem is, Go cannot automatically Decode into an object that uses the sql nullable variables. The modern approach is to use pointers, which can be nullable.
To Reproduce
In the below example, I have copied (a) the generated struct using supabase cli, (b) a sample response from a supabase rest call, and (c) the standard approach to decoding into a go object. As you can see, the error returns:
Run Online: https://go.dev/play/p/hOkZo4xt0bo
Expected behavior
The modern approach is to use pointers, which can be nullable. Another approach is to use custom wrappers with initializers, but this seems more cumbersome.
The text was updated successfully, but these errors were encountered: