entc/gen: add inc/dec capability for numeric fields

Reviewed By: alexsn

Differential Revision: D17259987

fbshipit-source-id: ad5ba1ba7383418463bc9137d82f16eadef809e7
This commit is contained in:
Ariel Mashraki
2019-09-10 05:59:04 -07:00
committed by Facebook Github Bot
parent b59fb59b9a
commit d820361a3a
28 changed files with 1218 additions and 434 deletions

View File

@@ -51,6 +51,12 @@ func OutV(args ...interface{}) *dsl.Traversal { return New().OutV(args...) }
// Values is the api for calling __.Values().
func Values(args ...string) *dsl.Traversal { return New().Values(args...) }
// Union is the api for calling __.Union().
func Union(args ...interface{}) *dsl.Traversal { return New().Union(args...) }
// Constant is the api for calling __.Constant().
func Constant(args ...interface{}) *dsl.Traversal { return New().Constant(args...) }
// OtherV is the api for calling __.OtherV().
func OtherV() *dsl.Traversal { return New().OtherV() }

View File

@@ -216,6 +216,11 @@ func TestTraverse(t *testing.T) {
wantQuery: "g.V().has($0, $1, $2).count().coalesce(__.is(neq($3)).constant($4), g.addV($5).property($6, $7).valueMap($8))",
wantBinds: dsl.Bindings{"$0": "person", "$1": "name", "$2": "a8m", "$3": 0, "$4": "unique constraint failed", "$5": "person", "$6": "name", "$7": "a8m", "$8": true},
},
{
input: g.V().Has("age").Property("age", __.Union(__.Values("age"), __.Constant(10)).Sum()).ValueMap(),
wantQuery: "g.V().has($0).property($1, __.union(__.values($2), __.constant($3)).sum()).valueMap()",
wantBinds: dsl.Bindings{"$0": "age", "$1": "age", "$2": "age", "$3": 10},
},
}
for i, tt := range tests {
tt := tt

View File

@@ -334,6 +334,11 @@ func (t *Traversal) Constant(args ...interface{}) *Traversal {
return t.Add(Dot, NewFunc("constant", args...))
}
// Union merges the results of an arbitrary number of traversals.
func (t *Traversal) Union(args ...interface{}) *Traversal {
return t.Add(Dot, NewFunc("union", args...))
}
// Each is a Groovy each-loop function.
func Each(v interface{}, cb func(it *Traversal) *Traversal) *Traversal {
t := &Traversal{}