-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Certain types, many stdlib (e.g. a net/netip.Prefix
) implement a:
These interfaces, notably encoding.TextUnmarshaler
/encoding.TextMarshaler
, should most likely be used where the DB field type supports it.
For example:
package main
import (
`net/netip`
)
type MyStruct struct {
ID uint `db:"id"`
Network netip.Prefix `db:"net"`
}
Preparing a named statement for this passes just fine (if nmStmt, err = db.PrepareNamed("INSERT INTO someTbl (id, net) VALUES (:id, :net);"); err != nil {...
).
However, upon actually trying to execute it (if res, err = nmStmt.Exec(&MyStruct{ID: 3, Network: netip.MustParsePrefix("192.168.1.0/24")}); err != nil {...
), the execution will fail with an unsupported type netip.Prefix, a struct
error.
Even if the target column data type is a SQLite TEXT
.
Now, because this is stdlib, I'd have to coerce type it, which leads to a lot of what is probably unnecessary code because this is a stdlib type that indicates that it can both marshal and unmarshal itself to/from both text and bytes.
Does sqlx do any sort of on-the-fly marshaling/unmarshaling like that, or is this likely instead an issue with the driver (in this case, the recommended github.com/mattn/go-sqlite3
per here)?