mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 04:40:49 +01:00
Use an idiomatic type switch for Scan type comparison
This commit is contained in:
parent
28bb8ff9f5
commit
c30673fb5f
1 changed files with 4 additions and 4 deletions
|
@ -471,22 +471,22 @@ func (d Decimal) MarshalJSON() ([]byte, error) {
|
||||||
func (d *Decimal) Scan(value interface{}) error {
|
func (d *Decimal) Scan(value interface{}) error {
|
||||||
var err error
|
var err error
|
||||||
// first try to see if the data is stored in database as a Numeric datatype
|
// first try to see if the data is stored in database as a Numeric datatype
|
||||||
switch value.(type) {
|
switch v := value.(type) {
|
||||||
|
|
||||||
case float64:
|
case float64:
|
||||||
// numeric in sqlite3 sends us float64
|
// numeric in sqlite3 sends us float64
|
||||||
*d = NewFromFloat(value.(float64))
|
*d = NewFromFloat(v)
|
||||||
return err
|
return err
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
// at least in sqlite3 when the value is 0 in db, the data is sent
|
// at least in sqlite3 when the value is 0 in db, the data is sent
|
||||||
// to us as an int64 instead of a float64 ...
|
// to us as an int64 instead of a float64 ...
|
||||||
*d = New(value.(int64), 0)
|
*d = New(v, 0)
|
||||||
return err
|
return err
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// default is trying to interpret value stored as string
|
// default is trying to interpret value stored as string
|
||||||
str, err := unquoteIfQuoted(value)
|
str, err := unquoteIfQuoted(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue