fix bug #7
This commit is contained in:
parent
d90967009a
commit
6ecfc78d8d
11
engine.go
11
engine.go
|
@ -207,9 +207,10 @@ func (engine *Engine) AutoMap(bean interface{}) *Table {
|
|||
}
|
||||
|
||||
func (engine *Engine) MapType(t reflect.Type) *Table {
|
||||
table := &Table{Name: engine.Mapper.Obj2Table(t.Name()), Type: t,
|
||||
Indexes: map[string][]string{}, Uniques: map[string][]string{}}
|
||||
table.Columns = make(map[string]*Column)
|
||||
table := NewTable()
|
||||
table.Name = engine.Mapper.Obj2Table(t.Name())
|
||||
table.Type = t
|
||||
|
||||
var idFieldColName string
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
|
@ -233,6 +234,7 @@ func (engine *Engine) MapType(t reflect.Type) *Table {
|
|||
for name, col := range parentTable.Columns {
|
||||
col.FieldName = fmt.Sprintf("%v.%v", fieldType.Name(), col.FieldName)
|
||||
table.Columns[name] = col
|
||||
table.ColumnsSeq = append(table.ColumnsSeq, name)
|
||||
}
|
||||
|
||||
table.PrimaryKey = parentTable.PrimaryKey
|
||||
|
@ -344,7 +346,8 @@ func (engine *Engine) MapType(t reflect.Type) *Table {
|
|||
if col.IsPrimaryKey {
|
||||
table.PrimaryKey = col.Name
|
||||
}
|
||||
table.Columns[col.Name] = col
|
||||
table.AddColumn(col)
|
||||
|
||||
if col.FieldName == "Id" || strings.HasSuffix(col.FieldName, ".Id") {
|
||||
idFieldColName = col.Name
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ func test(engine *xorm.Engine) {
|
|||
return
|
||||
}
|
||||
|
||||
engine.Pool.SetMaxConns(10)
|
||||
size := 100
|
||||
engine.Pool.SetMaxConns(50)
|
||||
size := 1000
|
||||
queue := make(chan int, size)
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
|
|
|
@ -212,7 +212,8 @@ func (statement *Statement) genColumnStr() string {
|
|||
|
||||
func (statement *Statement) genCreateSQL() string {
|
||||
sql := "CREATE TABLE IF NOT EXISTS " + statement.Engine.Quote(statement.TableName()) + " ("
|
||||
for _, col := range statement.RefTable.Columns {
|
||||
for _, colName := range statement.RefTable.ColumnsSeq {
|
||||
col := statement.RefTable.Columns[colName]
|
||||
sql += col.String(statement.Engine)
|
||||
sql = strings.TrimSpace(sql)
|
||||
sql += ", "
|
||||
|
|
13
table.go
13
table.go
|
@ -210,6 +210,7 @@ func (col *Column) ValueOf(bean interface{}) reflect.Value {
|
|||
type Table struct {
|
||||
Name string
|
||||
Type reflect.Type
|
||||
ColumnsSeq []string
|
||||
Columns map[string]*Column
|
||||
Indexes map[string][]string
|
||||
Uniques map[string][]string
|
||||
|
@ -220,6 +221,18 @@ func (table *Table) PKColumn() *Column {
|
|||
return table.Columns[table.PrimaryKey]
|
||||
}
|
||||
|
||||
func (table *Table) AddColumn(col *Column) {
|
||||
table.ColumnsSeq = append(table.ColumnsSeq, col.Name)
|
||||
table.Columns[col.Name] = col
|
||||
}
|
||||
|
||||
func NewTable() *Table {
|
||||
table := &Table{Indexes: map[string][]string{}, Uniques: map[string][]string{}}
|
||||
table.Columns = make(map[string]*Column)
|
||||
table.ColumnsSeq = make([]string, 0)
|
||||
return table
|
||||
}
|
||||
|
||||
type Conversion interface {
|
||||
FromDB([]byte) error
|
||||
ToDB() ([]byte, error)
|
||||
|
|
Loading…
Reference in New Issue