-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_builder.go
70 lines (61 loc) · 1.89 KB
/
select_builder.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package db
import (
"github.com/payshares/go/support/errors"
)
// Exec executes the query represented by the builder, populating the
// destination with the results returned by running the query against the
// current database session.
func (sb *SelectBuilder) Exec() error {
err := sb.Table.Session.Select(sb.dest, sb.sql)
if err != nil {
return errors.Wrap(err, "select failed")
}
return nil
}
// Limit is a passthrough call to the squirrel. See
// https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Limit
func (sb *SelectBuilder) Limit(limit uint64) *SelectBuilder {
sb.sql = sb.sql.Limit(limit)
return sb
}
// Offset is a passthrough call to the squirrel. See
// https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Offset
func (sb *SelectBuilder) Offset(offset uint64) *SelectBuilder {
sb.sql = sb.sql.Offset(offset)
return sb
}
// OrderBy is a passthrough call to the squirrel. See
// https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.OrderBy
func (sb *SelectBuilder) OrderBy(
orderBys ...string,
) *SelectBuilder {
sb.sql = sb.sql.OrderBy(orderBys...)
return sb
}
// Prefix is a passthrough call to the squirrel. See
// https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Prefix
func (sb *SelectBuilder) Prefix(
sql string,
args ...interface{},
) *SelectBuilder {
sb.sql = sb.sql.Prefix(sql, args...)
return sb
}
// Suffix is a passthrough call to the squirrel. See
// https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Suffix
func (sb *SelectBuilder) Suffix(
sql string,
args ...interface{},
) *SelectBuilder {
sb.sql = sb.sql.Suffix(sql, args...)
return sb
}
// Where is a passthrough call to the squirrel. See
// https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Where
func (sb *SelectBuilder) Where(
pred interface{},
args ...interface{},
) *SelectBuilder {
sb.sql = sb.sql.Where(pred, args...)
return sb
}