1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package types
- import (
- "database/sql/driver"
- )
- // NullInt is an implementation of a int for the MySQL type int/tinyint ....
- type NullInt int
- // Value implements the driver.Valuer interface,
- // and turns the bytes into a integer for MySQL storage.
- func (n NullInt) Value() (driver.Value, error) {
- return NullInt(n), nil
- }
- // Scan implements the sql.Scanner interface,
- // and turns the bytes incoming from MySQL into a integer
- func (n *NullInt) Scan(src interface{}) error {
- if src != nil {
- v, ok := src.(int64)
- if !ok {
- *n = NullInt(0)
- return nil
- //return errors.New("bad []byte type assertion")
- }
- *n = NullInt(v)
- return nil
- }
- *n = NullInt(0)
- return nil
- }
- // NullFloat is an implementation of a int for the MySQL type numeric ....
- type NullFloat float64
- // Value implements the driver.Valuer interface,
- // and turns the bytes into a integer for MySQL storage.
- func (n NullFloat) Value() (driver.Value, error) {
- return NullFloat(n), nil
- }
- // Scan implements the sql.Scanner interface,
- // and turns the bytes incoming from MySQL into a numeric
- func (n *NullFloat) Scan(src interface{}) error {
- if src != nil {
- v, ok := src.(float64)
- if !ok {
- *n = NullFloat(0)
- return nil
- //return errors.New("bad []byte type assertion (not float64)")
- }
- *n = NullFloat(v)
- return nil
- }
- *n = NullFloat(0)
- return nil
- }
|