join support builder

This commit is contained in:
Lunny Xiao 2018-06-09 16:17:14 +08:00
parent c68531db53
commit 0b04b2150f
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 21 additions and 2 deletions

View File

@ -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