entc/predicate: add isnull/notnull predicates for codegen

Reviewed By: idoshveki

Differential Revision: D16687226

fbshipit-source-id: 14a39e066447dbf77413e5c7f7318a2d61bddd32
This commit is contained in:
Ariel Mashraki
2019-08-07 06:53:00 -07:00
committed by Facebook Github Bot
parent 23059c8bae
commit 25f5a2ef01
27 changed files with 1060 additions and 44 deletions

View File

@@ -14,6 +14,9 @@ func Not(args ...interface{}) *dsl.Traversal { return New().Not(args...) }
// Has is the api for calling __.Has().
func Has(args ...interface{}) *dsl.Traversal { return New().Has(args...) }
// HasNot is the api for calling __.HasNot().
func HasNot(args ...interface{}) *dsl.Traversal { return New().HasNot(args...) }
// Or is the api for calling __.Or().
func Or(args ...interface{}) *dsl.Traversal { return New().Or(args...) }

View File

@@ -130,6 +130,11 @@ func TestTraverse(t *testing.T) {
wantQuery: "g.V().count()",
wantBinds: dsl.Bindings{},
},
{
input: g.V().HasNot("age"),
wantQuery: "g.V().hasNot($0)",
wantBinds: dsl.Bindings{"$0": "age"},
},
{
input: func() *dsl.Traversal {
v := g.V().HasID(1)

View File

@@ -112,6 +112,12 @@ func (t *Traversal) Has(args ...interface{}) *Traversal {
return t.Add(Dot, NewFunc("has", args...))
}
// HasNot filters vertices, edges and vertex properties based on the non-existence of properties.
// See: http://tinkerpop.apache.org/docs/current/reference/#has-step.
func (t *Traversal) HasNot(args ...interface{}) *Traversal {
return t.Add(Dot, NewFunc("hasNot", args...))
}
// HasID filters vertices, edges and vertex properties based on their identifier.
func (t *Traversal) HasID(args ...interface{}) *Traversal {
return t.Add(Dot, NewFunc("hasId", args...))

View File

@@ -191,6 +191,17 @@ func TestBuilder(t *testing.T) {
Where(NotNull("parent_id")),
wantQuery: "DELETE FROM `users` WHERE `parent_id` IS NOT NULL",
},
{
input: Delete("users").
Where(IsNull("parent_id")),
wantQuery: "DELETE FROM `users` WHERE `parent_id` IS NULL",
},
{
input: Delete("users").
Where(IsNull("parent_id").And().NotIn("name", "foo", "bar")),
wantQuery: "DELETE FROM `users` WHERE `parent_id` IS NULL AND `name` NOT IN (?, ?)",
wantArgs: []interface{}{"foo", "bar"},
},
{
input: Delete("users").
Where(False().And().False()),