feat: add uint64 surport

This commit is contained in:
guiqiang 2019-01-22 17:59:49 +08:00
parent cd690d0c9e
commit f778328e58
2 changed files with 163 additions and 148 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.git
*.swp
.idea/

View file

@ -87,6 +87,14 @@ func New(value int64, exp int32) Decimal {
}
}
// NewFromUint64 returns a new Decimal from a uint64, value * 10 ^ exp
func NewFromUint64(value uint64, exp int32) Decimal {
return Decimal{
value: new(big.Int).SetUint64(value),
exp: exp,
}
}
// NewFromBigInt returns a new Decimal from a big.Int, value * 10 ^ exp
func NewFromBigInt(value *big.Int, exp int32) Decimal {
return Decimal{
@ -988,6 +996,12 @@ func (d *Decimal) Scan(value interface{}) error {
*d = New(v, 0)
return nil
case uint64:
// at least in clickhouse when the value is 0 in db, the data is sent
// to us as an uint64 instead of a int64 ...
*d = NewFromUint64(v, 0)
return nil
default:
// default is trying to interpret value stored as string
str, err := unquoteIfQuoted(v)