improve time handling for gdb

This commit is contained in:
John
2019-10-25 19:54:02 +08:00
parent b373ace065
commit 734728fa9c
4 changed files with 22 additions and 10 deletions

View File

@ -2,5 +2,5 @@
# MySQL数据库配置
[database]
debug = true
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local"

View File

@ -2,20 +2,26 @@ package main
import (
"fmt"
"github.com/gogf/gf/database/gdb"
"time"
"github.com/gogf/gf/frame/g"
)
func main() {
db := g.DB()
// 开启调试模式以便于记录所有执行的SQL
//db := g.DB()
gdb.AddDefaultConfigNode(gdb.ConfigNode{
LinkInfo: "root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local",
Type: "mysql",
Charset: "utf8",
})
db, _ := gdb.New()
db.SetDebug(true)
fmt.Println(time.Now())
r, e := db.Table("user").Data(g.Map{
"create_time": time.Now().Local(),
}).Insert()
type User struct {
CreateTime time.Time `orm:"create_time"`
}
r, e := db.Table("user").Data(User{CreateTime: time.Now()}).Insert()
if e != nil {
panic(e)
}