Skip to content

Commit

Permalink
specify precision and scale for float and decimal types
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Aug 31, 2018
1 parent 8c2b6a4 commit 41bc1fd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions internal/pas/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"regexp"
"strconv"
)

const (
Expand All @@ -22,22 +23,28 @@ var propertyTypes = map[PropertyType]string{
TypeString: "varchar(2000)",
TypeInteger: "int",
TypeBigInteger: "bigint",
TypeFloat: "float",
TypeDouble: "double",
TypeFloat: "float(23, 2)",
TypeDouble: "double(53, 2)",
TypeDecimal: "decimal",
TypeBoolean: "tinyint(1)",
TypeDate: "date",
TypeDateTime: "datetime",
}

type Property struct {
Type PropertyType `json:"type"`
Name PropertyName `json:"name"`
Value interface{} `json:"value"`
Type PropertyType `json:"type"`
Name PropertyName `json:"name"`
Value interface{} `json:"value"`
Precision int `json:"precision"`
Scale int `json:"scale"`
}

func (p Property) dbType() string {
return propertyTypes[p.Type]
t := propertyTypes[p.Type]
if p.Type == TypeDecimal {
return t + "(" + strconv.Itoa(p.Precision) + "," + strconv.Itoa(p.Scale) + ")"
}
return t
}

type PropertyName string
Expand Down

0 comments on commit 41bc1fd

Please sign in to comment.