Support more numeric types.
This commit is contained in:
parent
31736ec13e
commit
371b6ce799
2 changed files with 32 additions and 1 deletions
|
|
@ -54,7 +54,9 @@ func (c ColumnInfo) GoBaseType() string {
|
|||
return "[]byte"
|
||||
case "text":
|
||||
return "string"
|
||||
case "numeric", "real":
|
||||
case "real":
|
||||
return "float32"
|
||||
case "numeric", "double precision":
|
||||
return "float64"
|
||||
default:
|
||||
return "string"
|
||||
|
|
|
|||
|
|
@ -87,3 +87,32 @@ func (n NullInt16) Value() (driver.Value, error) {
|
|||
}
|
||||
return n.Int16, nil
|
||||
}
|
||||
|
||||
type NullFloat32 struct {
|
||||
Float32 float32
|
||||
Valid bool // Valid is true if Int64 is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (n *NullFloat32) Scan(value interface{}) error {
|
||||
switch v := value.(type) {
|
||||
case float64:
|
||||
n.Float32, n.Valid = float32(v), true
|
||||
return nil
|
||||
case float32:
|
||||
n.Float32, n.Valid = v, true
|
||||
return nil
|
||||
}
|
||||
|
||||
n.Valid = false
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (n NullFloat32) Value() (driver.Value, error) {
|
||||
if !n.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return n.Float32, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue