bug fixed
This commit is contained in:
parent
9968697225
commit
769f6b3ae6
|
@ -0,0 +1,5 @@
|
|||
# Xorm Examples
|
||||
|
||||
Notice: all the examples will ask you install extra package `github.com/mattn/go-sqlite3`, since it depends on cgo. You have to compile it after you install a c++ compile. Please see [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3).
|
||||
|
||||
And then, you can run the examples via `go run xxx.go`. Every go file is a standalone example.
|
|
@ -22,7 +22,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
Orm.ShowSQL = true
|
||||
Orm.ShowSQL(true)
|
||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
|
||||
Orm.SetDefaultCacher(cacher)
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
engine.ShowSQL = true
|
||||
engine.ShowSQL(true)
|
||||
cacher := xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Hour, 1000)
|
||||
engine.SetDefaultCacher(cacher)
|
||||
fmt.Println(engine)
|
||||
|
@ -95,7 +95,7 @@ func main() {
|
|||
|
||||
fmt.Println("-----start mysql go routines-----")
|
||||
engine, err = mysqlEngine()
|
||||
engine.ShowSQL = true
|
||||
engine.ShowSQL(true)
|
||||
cacher = xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Hour, 1000)
|
||||
engine.SetDefaultCacher(cacher)
|
||||
if err != nil {
|
||||
|
|
|
@ -53,7 +53,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
Orm.ShowSQL = true
|
||||
Orm.ShowSQL(true)
|
||||
err = Orm.CreateTables(&User{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -34,7 +34,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
defer Orm.Close()
|
||||
Orm.ShowSQL = true
|
||||
Orm.ShowSQL(true)
|
||||
err = Orm.CreateTables(&User{}, &LoginInfo{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id int64
|
||||
Name string
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := "conversion.db"
|
||||
os.Remove(f)
|
||||
|
||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
Orm.ShowSQL(true)
|
||||
|
||||
err = Orm.CreateTables(&User{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = Orm.Insert(&User{Id: 1, Name: "xlw"})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
users := make([]User, 0)
|
||||
err = Orm.Find(&users)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(users)
|
||||
}
|
|
@ -33,7 +33,7 @@ func test(engine *xorm.Engine) {
|
|||
return
|
||||
}
|
||||
|
||||
engine.ShowSQL = true
|
||||
engine.ShowSQL(true)
|
||||
engine.SetMaxOpenConns(5)
|
||||
|
||||
size := 1000
|
||||
|
@ -91,7 +91,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
engine.ShowSQL = true
|
||||
engine.ShowSQL(true)
|
||||
fmt.Println(engine)
|
||||
test(engine)
|
||||
fmt.Println("------------------------")
|
||||
|
|
|
@ -32,7 +32,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
Orm.ShowSQL = true
|
||||
Orm.ShowSQL(true)
|
||||
err = Orm.CreateTables(&User{}, &LoginInfo{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -65,7 +65,7 @@ func main() {
|
|||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
Orm.ShowSQL = true
|
||||
Orm.ShowSQL(true)
|
||||
err = sync(Orm)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -20,7 +20,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
defer orm.Close()
|
||||
orm.ShowSQL = true
|
||||
orm.ShowSQL(true)
|
||||
|
||||
tables, err := orm.DBMetas()
|
||||
if err != nil {
|
||||
|
|
|
@ -457,7 +457,7 @@ func (session *Session) scanMapIntoStruct(obj interface{}, objMap map[string][]b
|
|||
fieldValue = dataStruct.FieldByName(fieldName)
|
||||
}
|
||||
if !fieldValue.IsValid() || !fieldValue.CanSet() {
|
||||
session.Engine.LogWarn("table %v's column %v is not valid or cannot set",
|
||||
session.Engine.LogWarnf("table %v's column %v is not valid or cannot set",
|
||||
table.Name, key)
|
||||
continue
|
||||
}
|
||||
|
@ -1568,7 +1568,7 @@ func (session *Session) dropAll() error {
|
|||
func (session *Session) getField(dataStruct *reflect.Value, key string, table *core.Table, idx int) *reflect.Value {
|
||||
var col *core.Column
|
||||
if col = table.GetColumnIdx(key, idx); col == nil {
|
||||
session.Engine.LogWarn(fmt.Sprintf("table %v has no column %v. %v", table.Name, key, table.ColumnsSeq()))
|
||||
session.Engine.LogWarnf("table %v has no column %v. %v", table.Name, key, table.ColumnsSeq())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1579,7 +1579,7 @@ func (session *Session) getField(dataStruct *reflect.Value, key string, table *c
|
|||
}
|
||||
|
||||
if !fieldValue.IsValid() || !fieldValue.CanSet() {
|
||||
session.Engine.LogWarn("table %v's column %v is not valid or cannot set",
|
||||
session.Engine.LogWarnf("table %v's column %v is not valid or cannot set",
|
||||
table.Name, key)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue