forked from goal-web/querybuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.go
27 lines (23 loc) · 906 Bytes
/
select.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
package querybuilder
import (
"fmt"
"github.com/goal-web/contracts"
)
func (this *Builder) Select(field string, fields ...string) contracts.QueryBuilder {
this.fields = append(fields, field)
return this
}
func (this *Builder) AddSelect(fields ...string) contracts.QueryBuilder {
this.fields = append(this.fields, fields...)
return this
}
func (this *Builder) SelectSub(provider contracts.QueryProvider, as string) contracts.QueryBuilder {
subBuilder := provider()
this.fields = []string{fmt.Sprintf("(%s) as %s", subBuilder.ToSql(), as)}
return this.addBinding(selectBinding, subBuilder.GetBindings()...)
}
func (this *Builder) AddSelectSub(provider contracts.QueryProvider, as string) contracts.QueryBuilder {
subBuilder := provider()
this.fields = append(this.fields, fmt.Sprintf("(%s) as %s", subBuilder.ToSql(), as))
return this.addBinding(selectBinding, subBuilder.GetBindings()...)
}