some gofmt & golint fixed
This commit is contained in:
parent
2189b36884
commit
664a52a6d7
4
doc.go
4
doc.go
|
@ -38,7 +38,7 @@ ORM Methods
|
||||||
|
|
||||||
There are 7 major ORM methods and many helpful methods to use to operate database.
|
There are 7 major ORM methods and many helpful methods to use to operate database.
|
||||||
|
|
||||||
1. Insert one or multipe records to database
|
1. Insert one or multiple records to database
|
||||||
|
|
||||||
affected, err := engine.Insert(&struct)
|
affected, err := engine.Insert(&struct)
|
||||||
// INSERT INTO struct () values ()
|
// INSERT INTO struct () values ()
|
||||||
|
@ -81,7 +81,7 @@ another is Rows
|
||||||
affected, err := engine.Id(...).Update(&user)
|
affected, err := engine.Id(...).Update(&user)
|
||||||
// UPDATE user SET ...
|
// UPDATE user SET ...
|
||||||
|
|
||||||
6. Delete one or more records, Delete MUST has conditon
|
6. Delete one or more records, Delete MUST has condition
|
||||||
|
|
||||||
affected, err := engine.Where(...).Delete(&user)
|
affected, err := engine.Where(...).Delete(&user)
|
||||||
// DELETE FROM user Where ...
|
// DELETE FROM user Where ...
|
||||||
|
|
16
engine.go
16
engine.go
|
@ -46,7 +46,7 @@ type Engine struct {
|
||||||
disableGlobalCache bool
|
disableGlobalCache bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowSQL show SQL statment or not on logger if log level is great than INFO
|
// ShowSQL show SQL statement or not on logger if log level is great than INFO
|
||||||
func (engine *Engine) ShowSQL(show ...bool) {
|
func (engine *Engine) ShowSQL(show ...bool) {
|
||||||
engine.logger.ShowSQL(show...)
|
engine.logger.ShowSQL(show...)
|
||||||
if len(show) == 0 {
|
if len(show) == 0 {
|
||||||
|
@ -56,7 +56,7 @@ func (engine *Engine) ShowSQL(show ...bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowExecTime show SQL statment and execute time or not on logger if log level is great than INFO
|
// ShowExecTime show SQL statement and execute time or not on logger if log level is great than INFO
|
||||||
func (engine *Engine) ShowExecTime(show ...bool) {
|
func (engine *Engine) ShowExecTime(show ...bool) {
|
||||||
if len(show) == 0 {
|
if len(show) == 0 {
|
||||||
engine.showExecTime = true
|
engine.showExecTime = true
|
||||||
|
@ -117,7 +117,7 @@ func (engine *Engine) SupportInsertMany() bool {
|
||||||
return engine.dialect.SupportInsertMany()
|
return engine.dialect.SupportInsertMany()
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuoteStr Engine's database use which charactor as quote.
|
// QuoteStr Engine's database use which character as quote.
|
||||||
// mysql, sqlite use ` and postgres use "
|
// mysql, sqlite use ` and postgres use "
|
||||||
func (engine *Engine) QuoteStr() string {
|
func (engine *Engine) QuoteStr() string {
|
||||||
return engine.dialect.QuoteStr()
|
return engine.dialect.QuoteStr()
|
||||||
|
@ -305,7 +305,7 @@ func (engine *Engine) Sql(querystring string, args ...interface{}) *Session {
|
||||||
return engine.SQL(querystring, args...)
|
return engine.SQL(querystring, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SQL method let's you manualy write raw SQL and operate
|
// SQL method let's you manually write raw SQL and operate
|
||||||
// For example:
|
// For example:
|
||||||
//
|
//
|
||||||
// engine.SQL("select * from user").Find(&users)
|
// engine.SQL("select * from user").Find(&users)
|
||||||
|
@ -716,7 +716,7 @@ func (engine *Engine) Select(str string) *Session {
|
||||||
return session.Select(str)
|
return session.Select(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cols only use the paramters as select or update columns
|
// Cols only use the parameters as select or update columns
|
||||||
func (engine *Engine) Cols(columns ...string) *Session {
|
func (engine *Engine) Cols(columns ...string) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = true
|
session.IsAutoClose = true
|
||||||
|
@ -740,15 +740,15 @@ func (engine *Engine) MustCols(columns ...string) *Session {
|
||||||
// UseBool xorm automatically retrieve condition according struct, but
|
// UseBool xorm automatically retrieve condition according struct, but
|
||||||
// if struct has bool field, it will ignore them. So use UseBool
|
// if struct has bool field, it will ignore them. So use UseBool
|
||||||
// to tell system to do not ignore them.
|
// to tell system to do not ignore them.
|
||||||
// If no paramters, it will use all the bool field of struct, or
|
// If no parameters, it will use all the bool field of struct, or
|
||||||
// it will use paramters's columns
|
// it will use parameters's columns
|
||||||
func (engine *Engine) UseBool(columns ...string) *Session {
|
func (engine *Engine) UseBool(columns ...string) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = true
|
session.IsAutoClose = true
|
||||||
return session.UseBool(columns...)
|
return session.UseBool(columns...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omit only not use the paramters as select or update columns
|
// Omit only not use the parameters as select or update columns
|
||||||
func (engine *Engine) Omit(columns ...string) *Session {
|
func (engine *Engine) Omit(columns ...string) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = true
|
session.IsAutoClose = true
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
@ -38,7 +39,7 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
users := make([]User, 0)
|
var users []User
|
||||||
err = Orm.Find(&users)
|
err = Orm.Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -47,8 +48,7 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("users:", users)
|
fmt.Println("users:", users)
|
||||||
|
|
||||||
users2 := make([]User, 0)
|
var users2 []User
|
||||||
|
|
||||||
err = Orm.Find(&users2)
|
err = Orm.Find(&users2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -57,8 +57,7 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("users2:", users2)
|
fmt.Println("users2:", users2)
|
||||||
|
|
||||||
users3 := make([]User, 0)
|
var users3 []User
|
||||||
|
|
||||||
err = Orm.Find(&users3)
|
err = Orm.Find(&users3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
|
|
@ -9,19 +9,21 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Status describes a status
|
||||||
type Status struct {
|
type Status struct {
|
||||||
Name string
|
Name string
|
||||||
Color string
|
Color string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// defines some statuses
|
||||||
var (
|
var (
|
||||||
Registed = Status{"Registed", "white"}
|
Registered = Status{"Registered", "white"}
|
||||||
Approved = Status{"Approved", "green"}
|
Approved = Status{"Approved", "green"}
|
||||||
Removed = Status{"Removed", "red"}
|
Removed = Status{"Removed", "red"}
|
||||||
Statuses = map[string]Status{
|
Statuses = map[string]Status{
|
||||||
Registed.Name: Registed,
|
Registered.Name: Registered,
|
||||||
Approved.Name: Approved,
|
Approved.Name: Approved,
|
||||||
Removed.Name: Removed,
|
Removed.Name: Removed,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ func (s *Status) ToDB() ([]byte, error) {
|
||||||
return []byte(s.Name), nil
|
return []byte(s.Name), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
@ -60,7 +63,7 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = Orm.Insert(&User{1, "xlw", Registed})
|
_, err = Orm.Insert(&User{1, "xlw", Registered})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -8,17 +8,20 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginInfo describes a login information
|
||||||
type LoginInfo struct {
|
type LoginInfo struct {
|
||||||
Id int64
|
Id int64
|
||||||
IP string
|
IP string
|
||||||
UserId int64
|
UserId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginInfo1 describes a login information
|
||||||
type LoginInfo1 struct {
|
type LoginInfo1 struct {
|
||||||
LoginInfo `xorm:"extends"`
|
LoginInfo `xorm:"extends"`
|
||||||
UserName string
|
UserName string
|
||||||
|
@ -28,27 +31,27 @@ func main() {
|
||||||
f := "derive.db"
|
f := "derive.db"
|
||||||
os.Remove(f)
|
os.Remove(f)
|
||||||
|
|
||||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
orm, err := xorm.NewEngine("sqlite3", f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer Orm.Close()
|
defer orm.Close()
|
||||||
Orm.ShowSQL(true)
|
orm.ShowSQL(true)
|
||||||
err = Orm.CreateTables(&User{}, &LoginInfo{})
|
err = orm.CreateTables(&User{}, &LoginInfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = Orm.Insert(&User{1, "xlw"}, &LoginInfo{1, "127.0.0.1", 1})
|
_, err = orm.Insert(&User{1, "xlw"}, &LoginInfo{1, "127.0.0.1", 1})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info := LoginInfo{}
|
info := LoginInfo{}
|
||||||
_, err = Orm.Id(1).Get(&info)
|
_, err = orm.Id(1).Get(&info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -56,7 +59,7 @@ func main() {
|
||||||
fmt.Println(info)
|
fmt.Println(info)
|
||||||
|
|
||||||
infos := make([]LoginInfo1, 0)
|
infos := make([]LoginInfo1, 0)
|
||||||
err = Orm.Sql(`select *, (select name from user where id = login_info.user_id) as user_name from
|
err = orm.Sql(`select *, (select name from user where id = login_info.user_id) as user_name from
|
||||||
login_info limit 10`).Find(&infos)
|
login_info limit 10`).Find(&infos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
@ -19,27 +20,27 @@ func main() {
|
||||||
f := "conversion.db"
|
f := "conversion.db"
|
||||||
os.Remove(f)
|
os.Remove(f)
|
||||||
|
|
||||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
orm, err := xorm.NewEngine("sqlite3", f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Orm.ShowSQL(true)
|
orm.ShowSQL(true)
|
||||||
|
|
||||||
err = Orm.CreateTables(&User{})
|
err = orm.CreateTables(&User{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = Orm.Insert(&User{Id: 1, Name: "xlw"})
|
_, err = orm.Insert(&User{Id: 1, Name: "xlw"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
users := make([]User, 0)
|
users := make([]User, 0)
|
||||||
err = Orm.Find(&users)
|
err = orm.Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
|
|
@ -8,11 +8,13 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User describes a user
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginInfo describes a login infomation
|
||||||
type LoginInfo struct {
|
type LoginInfo struct {
|
||||||
Id int64
|
Id int64
|
||||||
IP string
|
IP string
|
||||||
|
@ -27,26 +29,26 @@ func main() {
|
||||||
f := "singleMapping.db"
|
f := "singleMapping.db"
|
||||||
os.Remove(f)
|
os.Remove(f)
|
||||||
|
|
||||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
orm, err := xorm.NewEngine("sqlite3", f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Orm.ShowSQL(true)
|
orm.ShowSQL(true)
|
||||||
err = Orm.CreateTables(&User{}, &LoginInfo{})
|
err = orm.CreateTables(&User{}, &LoginInfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = Orm.Insert(&User{1, "xlw"}, &LoginInfo{1, "127.0.0.1", 1, "", 23})
|
_, err = orm.Insert(&User{1, "xlw"}, &LoginInfo{1, "127.0.0.1", 1, "", 23})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info := LoginInfo{}
|
info := LoginInfo{}
|
||||||
_, err = Orm.Id(1).Get(&info)
|
_, err = orm.Id(1).Get(&info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SyncUser2 describes a user
|
||||||
type SyncUser2 struct {
|
type SyncUser2 struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string `xorm:"unique"`
|
Name string `xorm:"unique"`
|
||||||
|
@ -20,6 +21,7 @@ type SyncUser2 struct {
|
||||||
Date int
|
Date int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyncLoginInfo2 describes a login information
|
||||||
type SyncLoginInfo2 struct {
|
type SyncLoginInfo2 struct {
|
||||||
Id int64
|
Id int64
|
||||||
IP string `xorm:"index"`
|
IP string `xorm:"index"`
|
||||||
|
|
|
@ -102,7 +102,7 @@ func splitTag(tag string) (tags []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lastIdx < len(tag) {
|
if lastIdx < len(tag) {
|
||||||
tags = append(tags, strings.TrimSpace(tag[lastIdx:len(tag)]))
|
tags = append(tags, strings.TrimSpace(tag[lastIdx:]))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,7 +465,7 @@ func (db *mysql) GetIndexes(tableName string) (map[string]*core.Index, error) {
|
||||||
colName = strings.Trim(colName, "` ")
|
colName = strings.Trim(colName, "` ")
|
||||||
var isRegular bool
|
var isRegular bool
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
indexName = indexName[5+len(tableName) : len(indexName)]
|
indexName = indexName[5+len(tableName):]
|
||||||
isRegular = true
|
isRegular = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1077,7 +1077,7 @@ func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")
|
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")
|
||||||
|
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
newIdxName := indexName[5+len(tableName) : len(indexName)]
|
newIdxName := indexName[5+len(tableName):]
|
||||||
if newIdxName != "" {
|
if newIdxName != "" {
|
||||||
indexName = newIdxName
|
indexName = newIdxName
|
||||||
}
|
}
|
||||||
|
|
10
session.go
10
session.go
|
@ -107,7 +107,7 @@ func (session *Session) resetStatement() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare set a flag to session that should be prepare statment before execute query
|
// Prepare set a flag to session that should be prepare statement before execute query
|
||||||
func (session *Session) Prepare() *Session {
|
func (session *Session) Prepare() *Session {
|
||||||
session.prepareStmt = true
|
session.prepareStmt = true
|
||||||
return session
|
return session
|
||||||
|
@ -250,8 +250,8 @@ func (session *Session) NoCascade() *Session {
|
||||||
// UseBool automatically retrieve condition according struct, but
|
// UseBool automatically retrieve condition according struct, but
|
||||||
// if struct has bool field, it will ignore them. So use UseBool
|
// if struct has bool field, it will ignore them. So use UseBool
|
||||||
// to tell system to do not ignore them.
|
// to tell system to do not ignore them.
|
||||||
// If no paramters, it will use all the bool field of struct, or
|
// If no parameters, it will use all the bool field of struct, or
|
||||||
// it will use paramters's columns
|
// it will use parameters's columns
|
||||||
func (session *Session) UseBool(columns ...string) *Session {
|
func (session *Session) UseBool(columns ...string) *Session {
|
||||||
session.Statement.UseBool(columns...)
|
session.Statement.UseBool(columns...)
|
||||||
return session
|
return session
|
||||||
|
@ -271,7 +271,7 @@ func (session *Session) ForUpdate() *Session {
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omit Only not use the paramters as select or update columns
|
// Omit Only not use the parameters as select or update columns
|
||||||
func (session *Session) Omit(columns ...string) *Session {
|
func (session *Session) Omit(columns ...string) *Session {
|
||||||
session.Statement.Omit(columns...)
|
session.Statement.Omit(columns...)
|
||||||
return session
|
return session
|
||||||
|
@ -1005,7 +1005,7 @@ func (session *Session) str2Time(col *core.Column, data string) (outTime time.Ti
|
||||||
sd, err := strconv.ParseInt(sdata, 10, 64)
|
sd, err := strconv.ParseInt(sdata, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
x = time.Unix(sd, 0)
|
x = time.Unix(sd, 0)
|
||||||
// !nashtsai! HACK mymysql driver is casuing Local location being change to CHAT and cause wrong time conversion
|
// !nashtsai! HACK mymysql driver is causing Local location being change to CHAT and cause wrong time conversion
|
||||||
if col.TimeZone == nil {
|
if col.TimeZone == nil {
|
||||||
x = x.In(session.Engine.TZLocation)
|
x = x.In(session.Engine.TZLocation)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -65,7 +65,8 @@ func (session *Session) nocacheGet(bean interface{}, sqlStr string, args ...inte
|
||||||
defer rawRows.Close()
|
defer rawRows.Close()
|
||||||
|
|
||||||
if rawRows.Next() {
|
if rawRows.Next() {
|
||||||
if fields, err := rawRows.Columns(); err == nil {
|
fields, err := rawRows.Columns()
|
||||||
|
if err == nil {
|
||||||
err = session.row2Bean(rawRows, fields, len(fields), bean)
|
err = session.row2Bean(rawRows, fields, len(fields), bean)
|
||||||
}
|
}
|
||||||
return true, err
|
return true, err
|
||||||
|
|
|
@ -406,7 +406,7 @@ func (db *sqlite3) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
|
|
||||||
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []")
|
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []")
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
index.Name = indexName[5+len(tableName) : len(indexName)]
|
index.Name = indexName[5+len(tableName):]
|
||||||
} else {
|
} else {
|
||||||
index.Name = indexName
|
index.Name = indexName
|
||||||
}
|
}
|
||||||
|
|
28
statement.go
28
statement.go
|
@ -75,7 +75,7 @@ type Statement struct {
|
||||||
cond builder.Cond
|
cond builder.Cond
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init reset all the statment's fields
|
// Init reset all the statement's fields
|
||||||
func (statement *Statement) Init() {
|
func (statement *Statement) Init() {
|
||||||
statement.RefTable = nil
|
statement.RefTable = nil
|
||||||
statement.Start = 0
|
statement.Start = 0
|
||||||
|
@ -147,12 +147,12 @@ func (statement *Statement) SQL(query interface{}, args ...interface{}) *Stateme
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where add Where statment
|
// Where add Where statement
|
||||||
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
||||||
return statement.And(query, args...)
|
return statement.And(query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// And add Where & and statment
|
// And add Where & and statement
|
||||||
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
||||||
switch query.(type) {
|
switch query.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
@ -173,7 +173,7 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Or add Where & Or statment
|
// Or add Where & Or statement
|
||||||
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
||||||
switch query.(type) {
|
switch query.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
@ -193,7 +193,7 @@ func (statement *Statement) Or(query interface{}, args ...interface{}) *Statemen
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// In generate "Where column IN (?) " statment
|
// In generate "Where column IN (?) " statement
|
||||||
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return statement
|
return statement
|
||||||
|
@ -204,7 +204,7 @@ func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotIn generate "Where column NOT IN (?) " statment
|
// NotIn generate "Where column NOT IN (?) " statement
|
||||||
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return statement
|
return statement
|
||||||
|
@ -706,14 +706,14 @@ func (statement *Statement) TableName() string {
|
||||||
return statement.tableName
|
return statement.tableName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"
|
// Id generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"
|
||||||
//
|
//
|
||||||
// Deprecated: use ID instead
|
// Deprecated: use ID instead
|
||||||
func (statement *Statement) Id(id interface{}) *Statement {
|
func (statement *Statement) Id(id interface{}) *Statement {
|
||||||
return statement.ID(id)
|
return statement.ID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"
|
// ID generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"
|
||||||
func (statement *Statement) ID(id interface{}) *Statement {
|
func (statement *Statement) ID(id interface{}) *Statement {
|
||||||
idValue := reflect.ValueOf(id)
|
idValue := reflect.ValueOf(id)
|
||||||
idType := reflect.TypeOf(idValue.Interface())
|
idType := reflect.TypeOf(idValue.Interface())
|
||||||
|
@ -741,7 +741,7 @@ func (statement *Statement) ID(id interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incr Generate "Update ... Set column = column + arg" statment
|
// Incr Generate "Update ... Set column = column + arg" statement
|
||||||
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
|
@ -752,7 +752,7 @@ func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decr Generate "Update ... Set column = column - arg" statment
|
// Decr Generate "Update ... Set column = column - arg" statement
|
||||||
func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
|
@ -763,24 +763,24 @@ func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExpr Generate "Update ... Set column = {expression}" statment
|
// SetExpr Generate "Update ... Set column = {expression}" statement
|
||||||
func (statement *Statement) SetExpr(column string, expression string) *Statement {
|
func (statement *Statement) SetExpr(column string, expression string) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
statement.exprColumns[k] = exprParam{column, expression}
|
statement.exprColumns[k] = exprParam{column, expression}
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = column + arg" statment
|
// Generate "Update ... Set column = column + arg" statement
|
||||||
func (statement *Statement) getInc() map[string]incrParam {
|
func (statement *Statement) getInc() map[string]incrParam {
|
||||||
return statement.incrColumns
|
return statement.incrColumns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = column - arg" statment
|
// Generate "Update ... Set column = column - arg" statement
|
||||||
func (statement *Statement) getDec() map[string]decrParam {
|
func (statement *Statement) getDec() map[string]decrParam {
|
||||||
return statement.decrColumns
|
return statement.decrColumns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = {expression}" statment
|
// Generate "Update ... Set column = {expression}" statement
|
||||||
func (statement *Statement) getExpr() map[string]exprParam {
|
func (statement *Statement) getExpr() map[string]exprParam {
|
||||||
return statement.exprColumns
|
return statement.exprColumns
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,15 +91,15 @@ func BenchmarkGetFlagForColumnWithICKey_ContainsKey(b *testing.B) {
|
||||||
|
|
||||||
mapCols := make(map[string]bool)
|
mapCols := make(map[string]bool)
|
||||||
cols := []*core.Column{
|
cols := []*core.Column{
|
||||||
&core.Column{Name: `ID`},
|
{Name: `ID`},
|
||||||
&core.Column{Name: `IsDeleted`},
|
{Name: `IsDeleted`},
|
||||||
&core.Column{Name: `Caption`},
|
{Name: `Caption`},
|
||||||
&core.Column{Name: `Code1`},
|
{Name: `Code1`},
|
||||||
&core.Column{Name: `Code2`},
|
{Name: `Code2`},
|
||||||
&core.Column{Name: `Code3`},
|
{Name: `Code3`},
|
||||||
&core.Column{Name: `ParentID`},
|
{Name: `ParentID`},
|
||||||
&core.Column{Name: `Latitude`},
|
{Name: `Latitude`},
|
||||||
&core.Column{Name: `Longitude`},
|
{Name: `Longitude`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, col := range cols {
|
for _, col := range cols {
|
||||||
|
@ -125,15 +125,15 @@ func BenchmarkGetFlagForColumnWithICKey_EmptyMap(b *testing.B) {
|
||||||
|
|
||||||
mapCols := make(map[string]bool)
|
mapCols := make(map[string]bool)
|
||||||
cols := []*core.Column{
|
cols := []*core.Column{
|
||||||
&core.Column{Name: `ID`},
|
{Name: `ID`},
|
||||||
&core.Column{Name: `IsDeleted`},
|
{Name: `IsDeleted`},
|
||||||
&core.Column{Name: `Caption`},
|
{Name: `Caption`},
|
||||||
&core.Column{Name: `Code1`},
|
{Name: `Code1`},
|
||||||
&core.Column{Name: `Code2`},
|
{Name: `Code2`},
|
||||||
&core.Column{Name: `Code3`},
|
{Name: `Code3`},
|
||||||
&core.Column{Name: `ParentID`},
|
{Name: `ParentID`},
|
||||||
&core.Column{Name: `Latitude`},
|
{Name: `Latitude`},
|
||||||
&core.Column{Name: `Longitude`},
|
{Name: `Longitude`},
|
||||||
}
|
}
|
||||||
|
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
|
|
Loading…
Reference in New Issue