Skip to content

Commit

Permalink
Fix #104. Depreacted 'nullable' for Neo4j>=2.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
versae committed May 16, 2014
1 parent f2d07c6 commit 0572dd9
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions neo4jrestclient/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import uuid
from collections import Sequence
import warnings

from neo4jrestclient.constants import RAW
from neo4jrestclient.request import Request
Expand Down Expand Up @@ -32,7 +33,7 @@ class BaseQ(object):
"eq", "equals", "neq", "notequals")

def __init__(self, property=None, lookup=None, match=None,
nullable=True, var=u"n", **kwargs):
nullable=None, var=u"n", **kwargs):
self._and = None
self._or = None
self._not = None
Expand All @@ -41,7 +42,7 @@ def __init__(self, property=None, lookup=None, match=None,
self.match = match
self.nullable = nullable
self.var = var
if property and (not self.lookup or self.match == None):
if property and (not self.lookup or self.match is None):
for m in self.matchs:
if m in kwargs:
self.lookup = m
Expand All @@ -53,7 +54,7 @@ def __init__(self, property=None, lookup=None, match=None,
" (%s) and a match case".format(all_matchs))

def is_valid(self):
return ((self.property and self.lookup and self.match != None) or
return ((self.property and self.lookup and self.match is not None) or
(self._and or self._or or self._not))

def _make_and(q1, q2):
Expand Down Expand Up @@ -215,10 +216,7 @@ def get_query_objects(self, var=None, prefix=None, params=None,
op_not = self._not.get_query_objects(params=params,
version=version)
params.update(op_not[1])
if version and version.split(".")[0] >= "2":
query = u"True = NOT ( {0} )".format(op_not[0])
else:
query = u"NOT ( {0} )".format(op_not[0])
query = u"NOT ( {0} )".format(op_not[0])
elif self._or is not None:
left_or = self._or[0].get_query_objects(params=params,
version=version)
Expand All @@ -241,29 +239,35 @@ def get_query_objects(self, var=None, prefix=None, params=None,
key = u"{0}p{1}".format(prefix, len(params))
prop = text_type(self.property).replace(u"`", u"\\`")
NEO4J_V2 = version and version.split(".")[0] >= "2"
if NEO4J_V2 and self.lookup == 'isnull':
if self.lookup == 'isnull':
query_format = ("{0}.`{1}` {2} NULL")
query = query_format.format(self.var, prop, lookup)
elif NEO4J_V2 and self.nullable is True:
try:
query_format = (u"(has({0}.`{1}`) and {2}.`{3}` "
u"{4} {{{5}}})")
query = query_format.format(self.var, prop,
self.var, prop,
lookup, key)
except AttributeError:
query = (u"( has(%s.`%s`) and %s.`%s` %s {%s} )"
% (self.var, prop, self.var, prop, lookup, key))
elif NEO4J_V2 and self.nullable is False:
try:
query_format = (u"(not(has({0}.`{1}`)) or {2}.`{3}` "
u"{4} {{{5}}})")
query = query_format.format(self.var, prop,
self.var, prop,
lookup, key)
except AttributeError:
query = (u"( not(has(%s.`%s`)) or %s.`%s` %s {%s} )"
% (self.var, prop, self.var, prop, lookup, key))
elif NEO4J_V2 and self.nullable is not None:
warnings.warn("Deprecated, Neo4j +2.0.0 does not support "
"the use of 'nullable' ('!' and '?' operators).",
DeprecationWarning)
if self.nullable is True:
try:
query_format = (u"(has({0}.`{1}`) and {2}.`{3}` "
u"{4} {{{5}}})")
query = query_format.format(self.var, prop,
self.var, prop,
lookup, key)
except AttributeError:
query = (u"( has(%s.`%s`) and %s.`%s` %s {%s} )"
% (self.var, prop, self.var, prop, lookup,
key))
elif self.nullable is False:
try:
query_format = (u"(not(has({0}.`{1}`)) or {2}.`{3}` "
u"{4} {{{5}}})")
query = query_format.format(self.var, prop,
self.var, prop,
lookup, key)
except AttributeError:
query = (u"( not(has(%s.`%s`)) or %s.`%s` %s {%s} )"
% (self.var, prop, self.var, prop, lookup,
key))
else:
if NEO4J_V2:
nullable = u""
Expand Down

0 comments on commit 0572dd9

Please sign in to comment.