1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 19:00:55 +00:00

Merge pull request #4190 from flycash/ftr/time-precision

Support precision
This commit is contained in:
Ming Deng 2020-08-26 12:45:17 +08:00 committed by GitHub
commit 14c911e9d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 77 deletions

View File

@ -1355,7 +1355,14 @@ setValue:
t time.Time t time.Time
err error err error
) )
if len(s) >= 19 {
if fi.timePrecision != nil && len(s) >= (20+*fi.timePrecision) {
layout := formatDateTime + "."
for i := 0; i < *fi.timePrecision; i++ {
layout += "0"
}
t, err = time.ParseInLocation(layout, s[:20+*fi.timePrecision], tz)
} else if len(s) >= 19 {
s = s[:19] s = s[:19]
t, err = time.ParseInLocation(formatDateTime, s, tz) t, err = time.ParseInLocation(formatDateTime, s, tz)
} else if len(s) >= 10 { } else if len(s) >= 10 {

View File

@ -44,24 +44,25 @@ var sqliteOperators = map[string]string{
// sqlite column types. // sqlite column types.
var sqliteTypes = map[string]string{ var sqliteTypes = map[string]string{
"auto": "integer NOT NULL PRIMARY KEY AUTOINCREMENT", "auto": "integer NOT NULL PRIMARY KEY AUTOINCREMENT",
"pk": "NOT NULL PRIMARY KEY", "pk": "NOT NULL PRIMARY KEY",
"bool": "bool", "bool": "bool",
"string": "varchar(%d)", "string": "varchar(%d)",
"string-char": "character(%d)", "string-char": "character(%d)",
"string-text": "text", "string-text": "text",
"time.Time-date": "date", "time.Time-date": "date",
"time.Time": "datetime", "time.Time": "datetime",
"int8": "tinyint", "time.Time-precision": "datetime(%d)",
"int16": "smallint", "int8": "tinyint",
"int32": "integer", "int16": "smallint",
"int64": "bigint", "int32": "integer",
"uint8": "tinyint unsigned", "int64": "bigint",
"uint16": "smallint unsigned", "uint8": "tinyint unsigned",
"uint32": "integer unsigned", "uint16": "smallint unsigned",
"uint64": "bigint unsigned", "uint32": "integer unsigned",
"float64": "real", "uint64": "bigint unsigned",
"float64-decimal": "decimal", "float64": "real",
"float64-decimal": "decimal",
} }
// sqlite dbBaser. // sqlite dbBaser.

View File

@ -145,55 +145,56 @@ type Data struct {
} }
type DataNull struct { type DataNull struct {
ID int `orm:"column(id)"` ID int `orm:"column(id)"`
Boolean bool `orm:"null"` Boolean bool `orm:"null"`
Char string `orm:"null;size(50)"` Char string `orm:"null;size(50)"`
Text string `orm:"null;type(text)"` Text string `orm:"null;type(text)"`
JSON string `orm:"type(json);null"` JSON string `orm:"type(json);null"`
Jsonb string `orm:"type(jsonb);null"` Jsonb string `orm:"type(jsonb);null"`
Time time.Time `orm:"null;type(time)"` Time time.Time `orm:"null;type(time)"`
Date time.Time `orm:"null;type(date)"` Date time.Time `orm:"null;type(date)"`
DateTime time.Time `orm:"null;column(datetime)"` DateTime time.Time `orm:"null;column(datetime)"`
Byte byte `orm:"null"` DateTimePrecision time.Time `orm:"null;type(datetime);precision(4)"`
Rune rune `orm:"null"` Byte byte `orm:"null"`
Int int `orm:"null"` Rune rune `orm:"null"`
Int8 int8 `orm:"null"` Int int `orm:"null"`
Int16 int16 `orm:"null"` Int8 int8 `orm:"null"`
Int32 int32 `orm:"null"` Int16 int16 `orm:"null"`
Int64 int64 `orm:"null"` Int32 int32 `orm:"null"`
Uint uint `orm:"null"` Int64 int64 `orm:"null"`
Uint8 uint8 `orm:"null"` Uint uint `orm:"null"`
Uint16 uint16 `orm:"null"` Uint8 uint8 `orm:"null"`
Uint32 uint32 `orm:"null"` Uint16 uint16 `orm:"null"`
Uint64 uint64 `orm:"null"` Uint32 uint32 `orm:"null"`
Float32 float32 `orm:"null"` Uint64 uint64 `orm:"null"`
Float64 float64 `orm:"null"` Float32 float32 `orm:"null"`
Decimal float64 `orm:"digits(8);decimals(4);null"` Float64 float64 `orm:"null"`
NullString sql.NullString `orm:"null"` Decimal float64 `orm:"digits(8);decimals(4);null"`
NullBool sql.NullBool `orm:"null"` NullString sql.NullString `orm:"null"`
NullFloat64 sql.NullFloat64 `orm:"null"` NullBool sql.NullBool `orm:"null"`
NullInt64 sql.NullInt64 `orm:"null"` NullFloat64 sql.NullFloat64 `orm:"null"`
BooleanPtr *bool `orm:"null"` NullInt64 sql.NullInt64 `orm:"null"`
CharPtr *string `orm:"null;size(50)"` BooleanPtr *bool `orm:"null"`
TextPtr *string `orm:"null;type(text)"` CharPtr *string `orm:"null;size(50)"`
BytePtr *byte `orm:"null"` TextPtr *string `orm:"null;type(text)"`
RunePtr *rune `orm:"null"` BytePtr *byte `orm:"null"`
IntPtr *int `orm:"null"` RunePtr *rune `orm:"null"`
Int8Ptr *int8 `orm:"null"` IntPtr *int `orm:"null"`
Int16Ptr *int16 `orm:"null"` Int8Ptr *int8 `orm:"null"`
Int32Ptr *int32 `orm:"null"` Int16Ptr *int16 `orm:"null"`
Int64Ptr *int64 `orm:"null"` Int32Ptr *int32 `orm:"null"`
UintPtr *uint `orm:"null"` Int64Ptr *int64 `orm:"null"`
Uint8Ptr *uint8 `orm:"null"` UintPtr *uint `orm:"null"`
Uint16Ptr *uint16 `orm:"null"` Uint8Ptr *uint8 `orm:"null"`
Uint32Ptr *uint32 `orm:"null"` Uint16Ptr *uint16 `orm:"null"`
Uint64Ptr *uint64 `orm:"null"` Uint32Ptr *uint32 `orm:"null"`
Float32Ptr *float32 `orm:"null"` Uint64Ptr *uint64 `orm:"null"`
Float64Ptr *float64 `orm:"null"` Float32Ptr *float32 `orm:"null"`
DecimalPtr *float64 `orm:"digits(8);decimals(4);null"` Float64Ptr *float64 `orm:"null"`
TimePtr *time.Time `orm:"null;type(time)"` DecimalPtr *float64 `orm:"digits(8);decimals(4);null"`
DatePtr *time.Time `orm:"null;type(date)"` TimePtr *time.Time `orm:"null;type(time)"`
DateTimePtr *time.Time `orm:"null"` DatePtr *time.Time `orm:"null;type(date)"`
DateTimePtr *time.Time `orm:"null"`
} }
type String string type String string
@ -297,13 +298,14 @@ func NewProfile() *Profile {
} }
type Post struct { type Post struct {
ID int `orm:"column(id)"` ID int `orm:"column(id)"`
User *User `orm:"rel(fk)"` User *User `orm:"rel(fk)"`
Title string `orm:"size(60)"` Title string `orm:"size(60)"`
Content string `orm:"type(text)"` Content string `orm:"type(text)"`
Created time.Time `orm:"auto_now_add"` Created time.Time `orm:"auto_now_add"`
Updated time.Time `orm:"auto_now"` Updated time.Time `orm:"auto_now"`
Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/client/orm.PostTags)"` UpdatedPrecision time.Time `orm:"auto_now;type(datetime);precision(4)"`
Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/client/orm.PostTags)"`
} }
func (u *Post) TableIndex() [][]string { func (u *Post) TableIndex() [][]string {
@ -504,7 +506,8 @@ var (
) )
func init() { func init() {
Debug, _ = StrTo(DBARGS.Debug).Bool() // Debug, _ = StrTo(DBARGS.Debug).Bool()
Debug = true
if DBARGS.Driver == "" || DBARGS.Source == "" { if DBARGS.Driver == "" || DBARGS.Source == "" {
fmt.Println(helpinfo) fmt.Println(helpinfo)