gocqlx
gocqlx copied to clipboard
Null value cannot be unpacked into *[16]uint8
When the value ProjectId
is value is null
in the database, I get these errors:
1:22AM ERR could not get by surfer email [email protected]
1:22AM ERR can not unmarshal X uuid into *[16]uint8
Here is the code. SurfersStruct
was generated using schemagen
:
type SurfersStruct struct {
Email string
Name string
ProjectId [16]byte
SurferId [16]byte
}
func (surfer *SurfersStruct) GetByEmail(session *gocqlx.Session, email string) {
stmt, names := qb.Select("brain.surfers").Where(qb.Eq("email")).Limit(1).ToCql()
res := session.Query(stmt, names).Bind(email)
if err := res.GetRelease(surfer); err != nil {
uy.Error("could not get by surfer email " + email)
uy.Error(err.Error())
}
}
I'm using github.com/scylladb/gocqlx/v2 v2.8.0
.
The two fixes I see are to change ProjectId
to a pointer *[16]byte
or to make sure project_id
is never null
in the database.
This seems like the most common use case, so I'm not sure if this is a bug, if I'm doing something wrong, or if this is expected behavior for a reason.
For now I think I'll fork schemagen to replace [16]byte
with *gocql.UUID
or gocql.UUID
.