Skip to content

Commit 079bbf1

Browse files
committed
fix join empty
1 parent 4c7101e commit 079bbf1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

builder/grammars/base.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func (b *baseGrammar) complieJoins(builder *FunBuilder) (sql string, err error)
9696
return "", nil
9797
}
9898
sql = ""
99-
for _, join := range builder.GetJoins() {
100-
99+
for i, join := range builder.GetJoins() {
101100
switch join.Type {
102101
case "join":
103102
sql += "join "
@@ -113,8 +112,10 @@ func (b *baseGrammar) complieJoins(builder *FunBuilder) (sql string, err error)
113112
sql += join.Table
114113
sql += " on "
115114
sql += join.Query
115+
if i != len(builder.GetJoins())-1 {
116+
sql += " "
117+
}
116118
}
117-
fmt.Println(sql)
118119
return
119120
}
120121

funsql_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func TestTable(t *testing.T) {
88
table := Table("a", "mysql")
99
sql, vals, err := table.
1010
Join("b", "a.id = b.a_id").
11+
Join("c", "c.id = b.a_id").
1112
Where("c", ">", 0).
1213
WhereIn("a", []int{1, 2, 3}).
1314
Group("a", "b").

0 commit comments

Comments
 (0)