join support builder
This commit is contained in:
parent
c68531db53
commit
0b04b2150f
21
statement.go
21
statement.go
|
@ -757,9 +757,28 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
|
|||
fmt.Fprintf(&buf, "%v JOIN ", joinOP)
|
||||
}
|
||||
|
||||
switch tp := tablename.(type) {
|
||||
case *builder.Builder:
|
||||
subSQL, subQueryArgs, err := tp.ToSQL()
|
||||
if err != nil {
|
||||
statement.lastError = err
|
||||
return statement
|
||||
}
|
||||
fmt.Fprintf(&buf, "(%s) ON %v", subSQL, condition)
|
||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||
case builder.Builder:
|
||||
subSQL, subQueryArgs, err := tp.ToSQL()
|
||||
if err != nil {
|
||||
statement.lastError = err
|
||||
return statement
|
||||
}
|
||||
fmt.Fprintf(&buf, "(%s) ON %v", subSQL, condition)
|
||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||
default:
|
||||
tbName := statement.Engine.TableName(tablename, true)
|
||||
|
||||
fmt.Fprintf(&buf, "%s ON %v", tbName, condition)
|
||||
}
|
||||
|
||||
statement.JoinStr = buf.String()
|
||||
statement.joinArgs = append(statement.joinArgs, args...)
|
||||
return statement
|
||||
|
|
Loading…
Reference in New Issue