-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.go
36 lines (30 loc) · 809 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
package sqeasy
import "strings"
// SelectColumns is a mapping of expression, like a column, to a destination variable
type SelectColumns []struct {
Expr string
Dest interface{}
}
// exprs returns the slice of expressions
func (sc SelectColumns) exprs() []string {
exprs := make([]string, len(sc))
for i, s := range sc {
exprs[i] = s.Expr
}
return exprs
}
// ExprList returns all the expressions separated by comma
// Use this in your SELECT statement
func (sc SelectColumns) ExprList() string {
return strings.Join(sc.exprs(), `,`)
}
// Scan copies the columns from the row into the values
func (sc SelectColumns) Scan(row interface {
Scan(dest ...interface{}) error
}) error {
dests := make([]interface{}, len(sc))
for i, s := range sc {
dests[i] = s.Dest
}
return row.Scan(dests...)
}