Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type KarmaDecimal struct {
- decimal.Decimal
- }
- // Scan implements the sql.Scanner interface for database deserialization.
- func (d *KarmaDecimal) Scan(value interface{}) error {
- // first try to see if the data is stored in database as a Numeric datatype
- switch v := value.(type) {
- case float32:
- old_d := decimal.NewFromFloat32(v)
- *d = KarmaDecimal{old_d}
- return nil
- case sql.NullFloat64:
- old_d := decimal.NewFromFloat(v.Float64)
- *d = KarmaDecimal{old_d}
- return nil
- default:
- return d.Decimal.Scan(value)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement