-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.go
More file actions
66 lines (58 loc) · 2.08 KB
/
options.go
File metadata and controls
66 lines (58 loc) · 2.08 KB
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
package q2sql
type ResourceSelectBuilderOption func(b *ResourceSelectBuilder)
// WithDefaultFields sets default fields which are used in the SELECT
// SQL statement in case if no specific fields are requested
func WithDefaultFields(fields []string) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
b.defaultFields = fields
}
}
// AllowFiltering sets filtering rules
func AllowFiltering(
allowedFilters AllowedConditions,
conditions ConditionFactory,
parser FilterExpressionParser,
) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
b.allowedConditions = allowedFilters
b.conditions = conditions
b.parser = parser
}
}
// AllowSelectFields allows to "SELECT" given fields
func AllowSelectFields(fields []string) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
if b.allowedSelectFields == nil {
b.allowedSelectFields = make(map[string]struct{})
}
fillMapKeys(b.allowedSelectFields, fields)
b.allowedSelectFieldsSlc = append(b.allowedSelectFieldsSlc, fields...)
}
}
// AllowSortingByFields allows to use specified fields in the "ORDER BY" SQL statement
func AllowSortingByFields(fields []string) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
b.allowedSortFields = fields
}
}
// Extend adds Extensions to the list
func Extend(extensions ...Extension) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
b.extensions = append(b.extensions, extensions...)
}
}
// AlwaysSelectFields sets fields which that will always be included in the SELECT
// SQL statement regardless if specific fields are requested or not
func AlwaysSelectFields(fields []string) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
b.alwaysSelectFields = fields
}
}
// AlwaysSelectAllFields will always include all allowed fields in the SELECT
// SQL statement regardless if specific fields are requested or not
// Overrides AlwaysSelectFields
func AlwaysSelectAllFields(flag bool) ResourceSelectBuilderOption {
return func(b *ResourceSelectBuilder) {
b.alwaysSelectAllFields = flag
}
}