mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 04:40:49 +01:00
Added support for Numeric type in db storage
This commit is contained in:
parent
9995dc92ee
commit
c4b5af094a
1 changed files with 8 additions and 0 deletions
|
@ -469,6 +469,14 @@ func (d Decimal) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
// Scan implements the sql.Scanner interface for database deserialization.
|
// Scan implements the sql.Scanner interface for database deserialization.
|
||||||
func (d *Decimal) Scan(value interface{}) error {
|
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)
|
str, err := unquoteIfQuoted(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue