mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 22:40:54 +00:00
Feature: implement the time precison for time.Time type
This commit is contained in:
parent
597c55d547
commit
7a94996e22
@ -66,7 +66,12 @@ checkColumn:
|
||||
case TypeDateField:
|
||||
col = T["time.Time-date"]
|
||||
case TypeDateTimeField:
|
||||
if fi.timePrecision == nil {
|
||||
col = T["time.Time"]
|
||||
} else {
|
||||
s := T["time.Time-precision"]
|
||||
col = fmt.Sprintf(s, *fi.timePrecision)
|
||||
}
|
||||
case TypeBitField:
|
||||
col = T["int8"]
|
||||
case TypeSmallIntegerField:
|
||||
|
@ -60,6 +60,7 @@ var mysqlTypes = map[string]string{
|
||||
"uint64": "bigint unsigned",
|
||||
"float64": "double precision",
|
||||
"float64-decimal": "numeric(%d, %d)",
|
||||
"time.Time-precision": "datetime(%d)",
|
||||
}
|
||||
|
||||
// mysql dbBaser implementation.
|
||||
|
@ -50,6 +50,7 @@ var oracleTypes = map[string]string{
|
||||
"uint64": "INTEGER",
|
||||
"float64": "NUMBER",
|
||||
"float64-decimal": "NUMBER(%d, %d)",
|
||||
"time.Time-precision": "TIMESTAMP(%d)",
|
||||
}
|
||||
|
||||
// oracle dbBaser
|
||||
|
@ -59,6 +59,7 @@ var postgresTypes = map[string]string{
|
||||
"float64-decimal": "numeric(%d, %d)",
|
||||
"json": "json",
|
||||
"jsonb": "jsonb",
|
||||
"time.Time-precision": "timestamp(%d) with time zone",
|
||||
}
|
||||
|
||||
// postgresql dbBaser.
|
||||
|
@ -137,6 +137,7 @@ type fieldInfo struct {
|
||||
isFielder bool // implement Fielder interface
|
||||
onDelete string
|
||||
description string
|
||||
timePrecision *int
|
||||
}
|
||||
|
||||
// new field info
|
||||
@ -177,7 +178,7 @@ func newFieldInfo(mi *modelInfo, field reflect.Value, sf reflect.StructField, mN
|
||||
decimals := tags["decimals"]
|
||||
size := tags["size"]
|
||||
onDelete := tags["on_delete"]
|
||||
|
||||
precision := tags["precision"]
|
||||
initial.Clear()
|
||||
if v, ok := tags["default"]; ok {
|
||||
initial.Set(v)
|
||||
@ -377,6 +378,18 @@ checkType:
|
||||
fi.index = false
|
||||
fi.unique = false
|
||||
case TypeTimeField, TypeDateField, TypeDateTimeField:
|
||||
if fieldType == TypeDateTimeField {
|
||||
if precision != "" {
|
||||
v, e := StrTo(precision).Int()
|
||||
if e != nil {
|
||||
err = fmt.Errorf("convert %s to int error:%v", precision, e)
|
||||
} else {
|
||||
fi.timePrecision = &v
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if attrs["auto_now"] {
|
||||
fi.autoNow = true
|
||||
} else if attrs["auto_now_add"] {
|
||||
|
@ -45,6 +45,7 @@ var supportTag = map[string]int{
|
||||
"on_delete": 2,
|
||||
"type": 2,
|
||||
"description": 2,
|
||||
"precision": 2,
|
||||
}
|
||||
|
||||
// get reflect.Type name with package path.
|
||||
|
Loading…
Reference in New Issue
Block a user