pg
pg copied to clipboard
Trigger UnmarshalText / MarshalText for big.Int
Hi, wondering if there is a way to trigger UnmarshalText/MarshalText on insert/select for a struct with a big.Int field. Unfortunately big.Int doesn't implement the Scan / Value serialization functions. I tried the following:
type Balance struct {
Amount *big.Int `sql:,type:text`
}
but that just inserts a {}
. I know I could create my own type like which is backed by a big.Int and implement the methods, but that would be a very large refactor in my current codebase. Inserting {}
is a bit unexpected and perhaps in this scenario we should just call MarshallText if available on the type?
Use this package : https://github.com/d-fal/bigint