From c4b5af094a73f8d8c4b35e3a905bf9df33d2e4ba Mon Sep 17 00:00:00 2001 From: Florent AIDE Date: Mon, 23 Nov 2015 16:43:59 +0100 Subject: [PATCH] Added support for Numeric type in db storage --- decimal.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/decimal.go b/decimal.go index e8d99b4..42acf30 100644 --- a/decimal.go +++ b/decimal.go @@ -469,6 +469,14 @@ func (d Decimal) MarshalJSON() ([]byte, error) { // Scan implements the sql.Scanner interface for database deserialization. func (d *Decimal) Scan(value interface{}) error { + var err error + // first try to see if the data is stored in database as a Numeric datatype + if val, ok := value.(float64); ok { + *d = NewFromFloat(val) + return err + } + + // then try to see if it is stored as a string str, err := unquoteIfQuoted(value) if err != nil { return err