pg icon indicating copy to clipboard operation
pg copied to clipboard

Trigger UnmarshalText / MarshalText for big.Int

Open connorwstein opened this issue 4 years ago • 1 comments

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?

connorwstein avatar May 01 '20 23:05 connorwstein

Use this package : https://github.com/d-fal/bigint

d-fal avatar Jul 18 '21 12:07 d-fal