-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
49 lines (40 loc) · 1.07 KB
/
option.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
package goqu_crud_gen
import (
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
)
type Option func(ds *goqu.SelectDataset)
// WithLockForUpdate option must be used for read methods to lock for update.
func WithLockForUpdate() Option {
return func(ds *goqu.SelectDataset) {
*ds = *ds.ForUpdate(exp.Wait)
}
}
// WithLimit option used to limit select.
func WithLimit(u uint) Option {
return func(ds *goqu.SelectDataset) {
*ds = *ds.Limit(u)
}
}
// WithOrder option used to order select.
func WithOrder(order ...exp.OrderedExpression) Option {
return func(ds *goqu.SelectDataset) {
*ds = *ds.Order(order...)
}
}
// WithFilter option used to filter select.
func WithFilter(exp ...exp.Expression) Option {
return func(ds *goqu.SelectDataset) {
*ds = *ds.Where(exp...)
}
}
type RepositoryOption func(o *RepositoryOpt)
type RepositoryOpt struct {
CtxTran CtxTransaction
}
// WithCtxTran option used to set custom transaction getter from context.
func WithCtxTran(ct CtxTransaction) RepositoryOption {
return func(o *RepositoryOpt) {
o.CtxTran = ct
}
}