-
Notifications
You must be signed in to change notification settings - Fork 1
/
entql.go
89 lines (75 loc) · 2.59 KB
/
entql.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Code generated by ent, DO NOT EDIT.
package generated
import (
"github.com/datumforge/go-template/internal/ent/generated/todo"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/entql"
"entgo.io/ent/schema/field"
)
// schemaGraph holds a representation of ent/schema at runtime.
var schemaGraph = func() *sqlgraph.Schema {
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 1)}
graph.Nodes[0] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: todo.Table,
Columns: todo.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: todo.FieldID,
},
},
Type: "Todo",
Fields: map[string]*sqlgraph.FieldSpec{
todo.FieldName: {Type: field.TypeString, Column: todo.FieldName},
todo.FieldDescription: {Type: field.TypeString, Column: todo.FieldDescription},
},
}
return graph
}()
// predicateAdder wraps the addPredicate method.
// All update, update-one and query builders implement this interface.
type predicateAdder interface {
addPredicate(func(s *sql.Selector))
}
// addPredicate implements the predicateAdder interface.
func (tq *TodoQuery) addPredicate(pred func(s *sql.Selector)) {
tq.predicates = append(tq.predicates, pred)
}
// Filter returns a Filter implementation to apply filters on the TodoQuery builder.
func (tq *TodoQuery) Filter() *TodoFilter {
return &TodoFilter{config: tq.config, predicateAdder: tq}
}
// addPredicate implements the predicateAdder interface.
func (m *TodoMutation) addPredicate(pred func(s *sql.Selector)) {
m.predicates = append(m.predicates, pred)
}
// Filter returns an entql.Where implementation to apply filters on the TodoMutation builder.
func (m *TodoMutation) Filter() *TodoFilter {
return &TodoFilter{config: m.config, predicateAdder: m}
}
// TodoFilter provides a generic filtering capability at runtime for TodoQuery.
type TodoFilter struct {
predicateAdder
config
}
// Where applies the entql predicate on the query filter.
func (f *TodoFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[0].Type, p, s); err != nil {
s.AddError(err)
}
})
}
// WhereID applies the entql string predicate on the id field.
func (f *TodoFilter) WhereID(p entql.StringP) {
f.Where(p.Field(todo.FieldID))
}
// WhereName applies the entql string predicate on the name field.
func (f *TodoFilter) WhereName(p entql.StringP) {
f.Where(p.Field(todo.FieldName))
}
// WhereDescription applies the entql string predicate on the description field.
func (f *TodoFilter) WhereDescription(p entql.StringP) {
f.Where(p.Field(todo.FieldDescription))
}