-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprojection_body.go
79 lines (72 loc) · 2.33 KB
/
projection_body.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
package db
import (
"github.com/rlch/neogo/internal"
"github.com/rlch/neogo/query"
)
// With adds configuration to a projection item for use in a [WITH] clause.
//
// [WITH]: https://neo4j.com/docs/cypher-manual/current/clauses/where/#usage-with-with-clause
func With(identifier query.Identifier, opts ...internal.ProjectionBodyOption) *internal.ProjectionBody {
m := &internal.ProjectionBody{}
m.Identifier = identifier
for _, opt := range opts {
internal.ConfigureProjectionBody(m, opt)
}
return m
}
// Return adds configuration to a projection item for use in a [RETURN] clause.
//
// [RETURN]: https://neo4j.com/docs/cypher-manual/current/clauses/return/
func Return(identifier query.Identifier, opts ...internal.ProjectionBodyOption) *internal.ProjectionBody {
return With(identifier, opts...)
}
// OrderBy adds an [ORDER BY] clause to a [With] or [Return] projection item.
// asc determines whether the ordering is ascending or descending.
//
// ORDER BY <identifier> [ASC|DESC]
//
// [ORDER BY]: https://neo4j.com/docs/cypher-manual/current/clauses/order-by/
func OrderBy(identifier query.PropertyIdentifier, asc bool) internal.ProjectionBodyOption {
return &internal.Configurer{
ProjectionBody: func(m *internal.ProjectionBody) {
if m.OrderBy == nil {
m.OrderBy = map[any]bool{}
}
m.OrderBy[identifier] = asc
},
}
}
// Skip adds a [SKIP] clause to a [With] or [Return] projection item.
//
// SKIP <expr>
//
// [SKIP]: https://neo4j.com/docs/cypher-manual/current/clauses/skip/
func Skip(expr string) internal.ProjectionBodyOption {
return &internal.Configurer{
ProjectionBody: func(m *internal.ProjectionBody) {
m.Skip = Expr(expr)
},
}
}
// Limit adds a [LIMIT] clause to a [With] or [Return] projection item.
//
// LIMIT <expr>
//
// [LIMIT]: https://neo4j.com/docs/cypher-manual/current/clauses/limit/
func Limit(expr string) internal.ProjectionBodyOption {
return &internal.Configurer{
ProjectionBody: func(m *internal.ProjectionBody) {
m.Limit = Expr(expr)
},
}
}
// Distinct adds a [DISTINCT] clause to a [With] or [Return] projection item.
//
// <clause> DISTINCT ...
//
// [DISTINCT]: https://neo4j.com/docs/cypher-manual/current/clauses/return/#query-return-distinct
var Distinct internal.ProjectionBodyOption = &internal.Configurer{
ProjectionBody: func(m *internal.ProjectionBody) {
m.Distinct = true
},
}