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