forked from goal-web/querybuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exists.go
39 lines (31 loc) · 1.23 KB
/
exists.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package querybuilder
import (
"fmt"
"github.com/goal-web/contracts"
)
func (this *Builder) WhereExists(provider contracts.QueryProvider, where ...contracts.WhereJoinType) contracts.QueryBuilder {
subBuilder := provider()
subSql := fmt.Sprintf("(%s)", subBuilder.ToSql())
if len(where) == 0 {
return this.addBinding(whereBinding, subBuilder.GetBindings()...).
Where("", "exists", subSql)
}
return this.addBinding(whereBinding, subBuilder.GetBindings()...).
Where("", "exists", subSql, where[0])
}
func (this *Builder) OrWhereExists(provider contracts.QueryProvider) contracts.QueryBuilder {
return this.WhereExists(provider, contracts.Or)
}
func (this *Builder) WhereNotExists(provider contracts.QueryProvider, where ...contracts.WhereJoinType) contracts.QueryBuilder {
subBuilder := provider()
subSql := fmt.Sprintf("(%s)", subBuilder.ToSql())
if len(where) == 0 {
return this.addBinding(whereBinding, subBuilder.GetBindings()...).
Where("", "not exists", subSql)
}
return this.addBinding(whereBinding, subBuilder.GetBindings()...).
Where("", "not exists", subSql, where[0])
}
func (this *Builder) OrWhereNotExists(provider contracts.QueryProvider) contracts.QueryBuilder {
return this.WhereNotExists(provider, contracts.Or)
}