-
Notifications
You must be signed in to change notification settings - Fork 37
/
select.go
47 lines (37 loc) · 943 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package clause
import (
"io"
"github.com/stephenafamo/bob"
)
type SelectList struct {
Columns []any
// necessary to be able to treat preloaders
// like any other query Mod
PreloadColumns []any
}
func (s *SelectList) CountSelectCols() int {
return len(s.Columns)
}
func (s *SelectList) SetSelect(columns ...any) {
s.Columns = columns
}
func (s *SelectList) AppendSelect(columns ...any) {
s.Columns = append(s.Columns, columns...)
}
func (s *SelectList) AppendPreloadSelect(columns ...any) {
s.PreloadColumns = append(s.PreloadColumns, columns...)
}
func (s SelectList) WriteSQL(w io.Writer, d bob.Dialect, start int) ([]any, error) {
var args []any
all := append(s.Columns, s.PreloadColumns...)
if len(all) > 0 {
colArgs, err := bob.ExpressSlice(w, d, start+len(args), all, "", ", ", "")
if err != nil {
return nil, err
}
args = append(args, colArgs...)
} else {
w.Write([]byte("*"))
}
return args, nil
}