bug fixed
This commit is contained in:
parent
e77fca31ae
commit
56700ee336
|
@ -515,7 +515,7 @@ func mappingTable(t reflect.Type, tableMapper core.IMapper, colMapper core.IMapp
|
|||
if col.Length2 == 0 {
|
||||
col.Length2 = col.SQLType.DefaultLength2
|
||||
}
|
||||
fmt.Println("======", col)
|
||||
//fmt.Println("======", col)
|
||||
if col.Name == "" {
|
||||
col.Name = colMapper.Obj2Table(t.Field(i).Name)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/lunny/xorm/caches"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -22,7 +24,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
Orm.ShowSQL = true
|
||||
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
|
||||
cacher := xorm.NewLRUCacher(caches.NewMemoryStore(), 1000)
|
||||
Orm.SetDefaultCacher(cacher)
|
||||
|
||||
err = Orm.CreateTables(&User{})
|
||||
|
|
|
@ -3,9 +3,10 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
|
@ -47,7 +48,7 @@ func main() {
|
|||
f := "conversion.db"
|
||||
os.Remove(f)
|
||||
|
||||
Orm, err := NewEngine("sqlite3", f)
|
||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
|
|
@ -2,9 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -27,7 +28,7 @@ func main() {
|
|||
f := "derive.db"
|
||||
os.Remove(f)
|
||||
|
||||
Orm, err := NewEngine("sqlite3", f)
|
||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
|
|
@ -2,11 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -38,14 +39,14 @@ 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)
|
||||
/*err = engine.(u)
|
||||
if err != nil {
|
||||
fmt.Println("Map user failed")
|
||||
} else {
|
||||
} else {*/
|
||||
for j := 0; j < 10; j++ {
|
||||
if x+j < 2 {
|
||||
_, err = engine.Get(u)
|
||||
|
@ -66,7 +67,7 @@ func test(engine *xorm.Engine) {
|
|||
}
|
||||
}
|
||||
fmt.Printf("%v success!\n", x)
|
||||
}
|
||||
//}
|
||||
}
|
||||
queue <- x
|
||||
}(i)
|
||||
|
@ -82,7 +83,7 @@ func test(engine *xorm.Engine) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(2)
|
||||
runtime.GOMAXPROCS(1)
|
||||
fmt.Println("-----start sqlite go routines-----")
|
||||
engine, err := sqliteEngine()
|
||||
if err != nil {
|
||||
|
|
|
@ -2,12 +2,12 @@ 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"
|
||||
"runtime"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -41,14 +41,14 @@ 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)
|
||||
/*err = engine.Map(u)
|
||||
if err != nil {
|
||||
fmt.Println("Map user failed")
|
||||
} else {
|
||||
} else {*/
|
||||
for j := 0; j < 10; j++ {
|
||||
if x+j < 2 {
|
||||
_, err = engine.Get(u)
|
||||
|
@ -69,7 +69,7 @@ func test(engine *xorm.Engine) {
|
|||
}
|
||||
}
|
||||
fmt.Printf("%v success!\n", x)
|
||||
}
|
||||
//}
|
||||
}
|
||||
queue <- x
|
||||
}(i)
|
||||
|
|
|
@ -2,9 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -16,12 +17,12 @@ func main() {
|
|||
f := "pool.db"
|
||||
os.Remove(f)
|
||||
|
||||
Orm, err := NewEngine("sqlite3", f)
|
||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
err = Orm.SetPool(NewSimpleConnectPool())
|
||||
err = Orm.SetPool(xorm.NewSimpleConnectPool())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
|
|
@ -2,9 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
|
@ -26,7 +27,7 @@ func main() {
|
|||
f := "singleMapping.db"
|
||||
os.Remove(f)
|
||||
|
||||
Orm, err := NewEngine("sqlite3", f)
|
||||
Orm, err := xorm.NewEngine("sqlite3", f)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
|
|
@ -588,7 +588,7 @@ func (statement *Statement) convertIdSql(sqlStr string) string {
|
|||
if len(sqls) != 2 {
|
||||
return ""
|
||||
}
|
||||
fmt.Println("-----", col)
|
||||
//fmt.Println("-----", col)
|
||||
newsql := fmt.Sprintf("SELECT %v.%v FROM %v", statement.Engine.Quote(statement.TableName()),
|
||||
statement.Engine.Quote(col.Name), sqls[1])
|
||||
return newsql
|
||||
|
|
6
xorm.go
6
xorm.go
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version string = "0.3.1"
|
||||
Version string = "0.4"
|
||||
)
|
||||
|
||||
func close(engine *Engine) {
|
||||
|
@ -75,3 +75,7 @@ func NewLRUCacher(store core.CacheStore, max int) *caches.LRUCacher {
|
|||
func NewLRUCacher2(store core.CacheStore, expired time.Duration, max int) *caches.LRUCacher {
|
||||
return caches.NewLRUCacher(store, expired, 0, max)
|
||||
}
|
||||
|
||||
func NewMemoryStore() *caches.MemoryStore {
|
||||
return caches.NewMemoryStore()
|
||||
}
|
||||
|
|
27
xorm/c++.go
27
xorm/c++.go
|
@ -2,9 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/lunny/xorm/core"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -18,27 +19,27 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
func cPlusTypeStr(col *xorm.Column) string {
|
||||
func cPlusTypeStr(col *core.Column) string {
|
||||
tp := col.SQLType
|
||||
name := strings.ToUpper(tp.Name)
|
||||
switch name {
|
||||
case xorm.Bit, xorm.TinyInt, xorm.SmallInt, xorm.MediumInt, xorm.Int, xorm.Integer, xorm.Serial:
|
||||
case core.Bit, core.TinyInt, core.SmallInt, core.MediumInt, core.Int, core.Integer, core.Serial:
|
||||
return "int"
|
||||
case xorm.BigInt, xorm.BigSerial:
|
||||
case core.BigInt, core.BigSerial:
|
||||
return "__int64"
|
||||
case xorm.Char, xorm.Varchar, xorm.TinyText, xorm.Text, xorm.MediumText, xorm.LongText:
|
||||
case core.Char, core.Varchar, core.TinyText, core.Text, core.MediumText, core.LongText:
|
||||
return "tstring"
|
||||
case xorm.Date, xorm.DateTime, xorm.Time, xorm.TimeStamp:
|
||||
case core.Date, core.DateTime, core.Time, core.TimeStamp:
|
||||
return "time_t"
|
||||
case xorm.Decimal, xorm.Numeric:
|
||||
case core.Decimal, core.Numeric:
|
||||
return "tstring"
|
||||
case xorm.Real, xorm.Float:
|
||||
case core.Real, core.Float:
|
||||
return "float"
|
||||
case xorm.Double:
|
||||
case core.Double:
|
||||
return "double"
|
||||
case xorm.TinyBlob, xorm.Blob, xorm.MediumBlob, xorm.LongBlob, xorm.Bytea:
|
||||
case core.TinyBlob, core.Blob, core.MediumBlob, core.LongBlob, core.Bytea:
|
||||
return "tstring"
|
||||
case xorm.Bool:
|
||||
case core.Bool:
|
||||
return "bool"
|
||||
default:
|
||||
return "tstring"
|
||||
|
@ -46,11 +47,11 @@ func cPlusTypeStr(col *xorm.Column) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func genCPlusImports(tables []*xorm.Table) map[string]string {
|
||||
func genCPlusImports(tables []*core.Table) map[string]string {
|
||||
imports := make(map[string]string)
|
||||
|
||||
for _, table := range tables {
|
||||
for _, col := range table.Columns {
|
||||
for _, col := range table.Columns() {
|
||||
switch cPlusTypeStr(col) {
|
||||
case "time_t":
|
||||
imports[`<time.h>`] = `<time.h>`
|
||||
|
|
21
xorm/go.go
21
xorm/go.go
|
@ -3,11 +3,11 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lunny/xorm"
|
||||
"go/format"
|
||||
"reflect"
|
||||
"strings"
|
||||
"text/template"
|
||||
"github.com/lunny/xorm/core"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -157,7 +157,7 @@ func gt(arg1, arg2 interface{}) (bool, error) {
|
|||
return !lessOrEqual, nil
|
||||
}
|
||||
|
||||
func getCol(cols map[string]*xorm.Column, name string) *xorm.Column {
|
||||
func getCol(cols map[string]*core.Column, name string) *core.Column {
|
||||
return cols[name]
|
||||
}
|
||||
|
||||
|
@ -169,11 +169,11 @@ func formatGo(src string) (string, error) {
|
|||
return string(source), nil
|
||||
}
|
||||
|
||||
func genGoImports(tables []*xorm.Table) map[string]string {
|
||||
func genGoImports(tables []*core.Table) map[string]string {
|
||||
imports := make(map[string]string)
|
||||
|
||||
for _, table := range tables {
|
||||
for _, col := range table.Columns {
|
||||
for _, col := range table.Columns() {
|
||||
if typestring(col) == "time.Time" {
|
||||
imports["time"] = "time"
|
||||
}
|
||||
|
@ -182,12 +182,9 @@ func genGoImports(tables []*xorm.Table) map[string]string {
|
|||
return imports
|
||||
}
|
||||
|
||||
func typestring(col *xorm.Column) string {
|
||||
func typestring(col *core.Column) string {
|
||||
st := col.SQLType
|
||||
/*if col.IsPrimaryKey {
|
||||
return "int64"
|
||||
}*/
|
||||
t := xorm.SQLType2Type(st)
|
||||
t := core.SQLType2Type(st)
|
||||
s := t.String()
|
||||
if s == "[]uint8" {
|
||||
return "[]byte"
|
||||
|
@ -195,7 +192,7 @@ func typestring(col *xorm.Column) string {
|
|||
return s
|
||||
}
|
||||
|
||||
func tag(table *xorm.Table, col *xorm.Column) string {
|
||||
func tag(table *core.Table, col *core.Column) string {
|
||||
isNameId := (mapper.Table2Obj(col.Name) == "Id")
|
||||
isIdPk := isNameId && typestring(col) == "int64"
|
||||
|
||||
|
@ -227,9 +224,9 @@ func tag(table *xorm.Table, col *xorm.Column) string {
|
|||
for name, _ := range col.Indexes {
|
||||
index := table.Indexes[name]
|
||||
var uistr string
|
||||
if index.Type == xorm.UniqueType {
|
||||
if index.Type == core.UniqueType {
|
||||
uistr = "unique"
|
||||
} else if index.Type == xorm.IndexType {
|
||||
} else if index.Type == core.IndexType {
|
||||
uistr = "index"
|
||||
}
|
||||
if len(index.Cols) > 1 {
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/lunny/xorm"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"text/template"
|
||||
"github.com/lunny/xorm/core"
|
||||
)
|
||||
|
||||
type LangTmpl struct {
|
||||
Funcs template.FuncMap
|
||||
Formater func(string) (string, error)
|
||||
GenImports func([]*xorm.Table) map[string]string
|
||||
GenImports func([]*core.Table) map[string]string
|
||||
}
|
||||
|
||||
var (
|
||||
mapper = &xorm.SnakeMapper{}
|
||||
mapper = &core.SnakeMapper{}
|
||||
langTmpls = map[string]LangTmpl{
|
||||
"go": GoLangTmpl,
|
||||
"c++": CPlusTmpl,
|
||||
|
|
|
@ -3,18 +3,20 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
_ "github.com/bylevel/pq"
|
||||
"github.com/dvirsky/go-pylog/logging"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/ziutek/mymysql/godrv"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"text/template"
|
||||
|
||||
_ "github.com/bylevel/pq"
|
||||
"github.com/dvirsky/go-pylog/logging"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lunny/xorm"
|
||||
"github.com/lunny/xorm/core"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/ziutek/mymysql/godrv"
|
||||
)
|
||||
|
||||
var CmdReverse = &Command{
|
||||
|
@ -48,7 +50,7 @@ func printReversePrompt(flag string) {
|
|||
}
|
||||
|
||||
type Tmpl struct {
|
||||
Tables []*xorm.Table
|
||||
Tables []*core.Table
|
||||
Imports map[string]string
|
||||
Model string
|
||||
}
|
||||
|
@ -188,7 +190,7 @@ func runReverse(cmd *Command, args []string) {
|
|||
|
||||
imports := langTmpl.GenImports(tables)
|
||||
|
||||
tbls := make([]*xorm.Table, 0)
|
||||
tbls := make([]*core.Table, 0)
|
||||
for _, table := range tables {
|
||||
tbls = append(tbls, table)
|
||||
}
|
||||
|
@ -223,7 +225,7 @@ func runReverse(cmd *Command, args []string) {
|
|||
} else {
|
||||
for _, table := range tables {
|
||||
// imports
|
||||
tbs := []*xorm.Table{table}
|
||||
tbs := []*core.Table{table}
|
||||
imports := langTmpl.GenImports(tbs)
|
||||
|
||||
w, err := os.OpenFile(path.Join(genDir, unTitle(mapper.Table2Obj(table.Name))+ext), os.O_RDWR|os.O_CREATE, 0600)
|
||||
|
|
Loading…
Reference in New Issue