-
Notifications
You must be signed in to change notification settings - Fork 4
/
filters.go
61 lines (48 loc) · 1.4 KB
/
filters.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
package actions
import (
"fmt"
"github.com/teamkeel/keel/proto"
"github.com/teamkeel/keel/schema/parser"
)
// Applies all implicit input filters to the query.
func (query *QueryBuilder) applyImplicitFilters(scope *Scope, args map[string]any) error {
message := proto.FindWhereInputMessage(scope.Schema, scope.Action.Name)
if message == nil {
return nil
}
for _, input := range message.Fields {
if !input.IsModelField() {
// Skip if this is an explicit input (probably used in a @where)
continue
}
fieldName := input.Name
value, ok := args[fieldName]
if !ok {
return fmt.Errorf("this expected input: %s, is missing from this provided args map: %+v", fieldName, args)
}
err := query.whereByImplicitFilter(scope, input.Target, fieldName, Equals, value)
if err != nil {
return err
}
// Implicit input filters are ANDed together
query.And()
}
return nil
}
// Applies all exlicit where attribute filters to the query.
func (query *QueryBuilder) applyExplicitFilters(scope *Scope, args map[string]any) error {
for _, where := range scope.Action.WhereExpressions {
expression, err := parser.ParseExpression(where.Source)
if err != nil {
return err
}
// Resolve the database statement for this expression
err = query.whereByExpression(scope, expression, args)
if err != nil {
return err
}
// Where attributes are ANDed together
query.And()
}
return nil
}