bug fixed
This commit is contained in:
parent
bb6a9c24fa
commit
98d4c0e000
44
base_test.go
44
base_test.go
|
@ -388,6 +388,12 @@ func testdelete(engine *Engine, t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type NoIdUser struct {
|
||||
User string `xorm:"unique"`
|
||||
Remain int64
|
||||
Total int64
|
||||
}
|
||||
|
||||
func get(engine *Engine, t *testing.T) {
|
||||
user := Userinfo{Uid: 2}
|
||||
|
||||
|
@ -401,6 +407,44 @@ func get(engine *Engine, t *testing.T) {
|
|||
} else {
|
||||
fmt.Println("no record id is 2")
|
||||
}
|
||||
|
||||
err = engine.Sync(&NoIdUser{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = engine.Where("`user` = ?", "xlw").Delete(&NoIdUser{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cnt, err := engine.Insert(&NoIdUser{"xlw", 20, 100})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if cnt != 1 {
|
||||
err = errors.New("insert not returned 1")
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
noIdUser := new(NoIdUser)
|
||||
has, err = engine.Where("`user` = ?", "xlw").Get(noIdUser)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !has {
|
||||
err = errors.New("get not returned 1")
|
||||
t.Error(err)
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(noIdUser)
|
||||
}
|
||||
|
||||
func cascadeGet(engine *Engine, t *testing.T) {
|
||||
|
|
|
@ -2,9 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
. "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -16,13 +16,13 @@ func main() {
|
|||
f := "cache.db"
|
||||
os.Remove(f)
|
||||
|
||||
Orm, err := NewEngine("sqlite3", f)
|
||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
Orm.ShowSQL = true
|
||||
cacher := NewLRUCacher(NewMemoryStore(), 1000)
|
||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
|
||||
Orm.SetDefaultCacher(cacher)
|
||||
|
||||
err = Orm.CreateTables(&User{})
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
//xorm "github.com/lunny/xorm"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
//"time"
|
||||
//"sync/atomic"
|
||||
xorm "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -40,13 +37,9 @@ func test(engine *xorm.Engine) {
|
|||
for i := 0; i < size; i++ {
|
||||
go func(x int) {
|
||||
//x := i
|
||||
err := engine.Test()
|
||||
err := engine.Ping()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
err = engine.Map(u)
|
||||
if err != nil {
|
||||
fmt.Println("Map user failed")
|
||||
} else {
|
||||
for j := 0; j < 10; j++ {
|
||||
if x+j < 2 {
|
||||
|
@ -70,7 +63,6 @@ func test(engine *xorm.Engine) {
|
|||
}
|
||||
fmt.Printf("%v success!\n", x)
|
||||
}
|
||||
}
|
||||
queue <- x
|
||||
}(i)
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
. "xorm"
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
|
|
|
@ -2,9 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
. "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
//xorm "github.com/lunny/xorm"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
//"time"
|
||||
//"sync/atomic"
|
||||
"runtime"
|
||||
xorm "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
|
@ -3,13 +3,11 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
xorm "github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
//"time"
|
||||
//"sync/atomic"
|
||||
"runtime"
|
||||
//xorm "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
|
@ -2,9 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
. "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
|
@ -2,9 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
. "xorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
_ "github.com/bylevel/pq"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"xorm"
|
||||
)
|
||||
|
||||
type SyncUser2 struct {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package xorm
|
||||
|
||||
import (
|
||||
//"reflect"
|
||||
//"strings"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// name translation between struct, fields names and table, column names
|
||||
|
@ -71,6 +70,8 @@ func titleCasedName(name string) string {
|
|||
newstr := make([]rune, 0)
|
||||
upNextChar := true
|
||||
|
||||
name = strings.ToLower(name)
|
||||
|
||||
for _, chr := range name {
|
||||
switch {
|
||||
case upNextChar:
|
||||
|
|
|
@ -876,7 +876,6 @@ func (session *Session) Iterate(bean interface{}, fun IterFunc) error {
|
|||
// get retrieve one record from database, bean's non-empty fields
|
||||
// will be as conditions
|
||||
func (session *Session) Get(bean interface{}) (bool, error) {
|
||||
|
||||
err := session.newDb()
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
[deps]
|
||||
github.com/lunny/xorm=../
|
12
xorm/go.go
12
xorm/go.go
|
@ -184,9 +184,9 @@ func genGoImports(tables []*xorm.Table) map[string]string {
|
|||
|
||||
func typestring(col *xorm.Column) string {
|
||||
st := col.SQLType
|
||||
if col.IsPrimaryKey {
|
||||
/*if col.IsPrimaryKey {
|
||||
return "int64"
|
||||
}
|
||||
}*/
|
||||
t := xorm.SQLType2Type(st)
|
||||
s := t.String()
|
||||
if s == "[]uint8" {
|
||||
|
@ -197,14 +197,16 @@ func typestring(col *xorm.Column) string {
|
|||
|
||||
func tag(table *xorm.Table, col *xorm.Column) string {
|
||||
isNameId := (mapper.Table2Obj(col.Name) == "Id")
|
||||
isIdPk := isNameId && typestring(col) == "int64"
|
||||
|
||||
res := make([]string, 0)
|
||||
if !col.Nullable {
|
||||
if !isNameId {
|
||||
if !isIdPk {
|
||||
res = append(res, "not null")
|
||||
}
|
||||
}
|
||||
if col.IsPrimaryKey {
|
||||
if !isNameId {
|
||||
if !isIdPk {
|
||||
res = append(res, "pk")
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +214,7 @@ func tag(table *xorm.Table, col *xorm.Column) string {
|
|||
res = append(res, "default "+col.Default)
|
||||
}
|
||||
if col.IsAutoIncrement {
|
||||
if !isNameId {
|
||||
if !isIdPk {
|
||||
res = append(res, "autoincr")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func init() {
|
|||
|
||||
var engine *xorm.Engine
|
||||
|
||||
func help() {
|
||||
func shellHelp() {
|
||||
fmt.Println(`
|
||||
show tables show all tables
|
||||
columns <table_name> show table's column info
|
||||
|
@ -127,12 +127,12 @@ func runShell(cmd *Command, args []string) {
|
|||
}
|
||||
}
|
||||
} else if lcmd == "show tables;" {
|
||||
tables, err := engine.DBMetas()
|
||||
/*tables, err := engine.DBMetas()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
cnt, err := engine.Exec(scmd)
|
||||
if err != nil {
|
||||
|
|
|
@ -18,6 +18,8 @@ import (
|
|||
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
||||
const go11tag = true
|
||||
|
||||
const version = "0.1"
|
||||
|
||||
// Commands lists the available commands and help topics.
|
||||
// The order here is the order in which they are printed by 'gopm help'.
|
||||
var commands = []*Command{
|
||||
|
@ -70,7 +72,6 @@ func setExitStatus(n int) {
|
|||
}
|
||||
|
||||
var usageTemplate = `xorm is a database tool based xorm package.
|
||||
|
||||
Usage:
|
||||
|
||||
xorm command [arguments]
|
||||
|
|
Loading…
Reference in New Issue