Join add struct support
This commit is contained in:
parent
84d678f941
commit
c3b84c6ae2
19
statement.go
19
statement.go
|
@ -766,12 +766,13 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
|
||||||
var table string
|
var table string
|
||||||
if l > 0 {
|
if l > 0 {
|
||||||
f := t[0]
|
f := t[0]
|
||||||
v := rValue(f)
|
switch f.(type) {
|
||||||
t := v.Type()
|
case string:
|
||||||
if t.Kind() == reflect.String {
|
|
||||||
table = f.(string)
|
table = f.(string)
|
||||||
} else if t.Kind() == reflect.Struct {
|
case TableName:
|
||||||
table = statement.Engine.tbName(v)
|
table = f.(TableName).TableName()
|
||||||
|
default:
|
||||||
|
// FIXME: error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if l > 1 {
|
if l > 1 {
|
||||||
|
@ -782,9 +783,17 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
|
||||||
}
|
}
|
||||||
case TableName:
|
case TableName:
|
||||||
fmt.Fprintf(&buf, tablename.(TableName).TableName())
|
fmt.Fprintf(&buf, tablename.(TableName).TableName())
|
||||||
|
case string:
|
||||||
|
fmt.Fprintf(&buf, tablename.(string))
|
||||||
default:
|
default:
|
||||||
|
v := rValue(tablename)
|
||||||
|
t := v.Type()
|
||||||
|
if t.Kind() == reflect.Struct {
|
||||||
|
fmt.Fprintf(&buf, statement.Engine.tbName(v))
|
||||||
|
} else {
|
||||||
fmt.Fprintf(&buf, statement.Engine.Quote(fmt.Sprintf("%v", tablename)))
|
fmt.Fprintf(&buf, statement.Engine.Quote(fmt.Sprintf("%v", tablename)))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(&buf, " ON %v", condition)
|
fmt.Fprintf(&buf, " ON %v", condition)
|
||||||
statement.JoinStr = buf.String()
|
statement.JoinStr = buf.String()
|
||||||
|
|
Loading…
Reference in New Issue