-
Notifications
You must be signed in to change notification settings - Fork 232
Match API
Robin Edwards edited this page Jan 30, 2014
·
21 revisions
(Used to be called traverse()
)
class Address(StructuredNode):
name = StringProperty()
street = StringProperty()
town = StringProperty()
post_code = StringProperty()
class Car(StructuredNode):
model = StringProperty(unique_index=True)
class User(StructuredNode):
name = StringProperty(unique_index=True)
age = IntegerProperty()
friend = Relationship(Address, 'FRIEND', ZeroOrMore)
address = Relationship(Address, 'ADDRESS', ZeroOrOne)
car = Relationship(Address, 'CAR', ZeroOrOne)
User.filter(age__lt=16)
User.exclude(age__lt=16)
# chain able:
User.filter(age__lt=16).exclude(age__lt=4)
jim.friends.all()
# only where rel property since is less than year
jim.friends.match(since__lt=year())
# replaces search() as that is now deprecated
jim.friends.filter(age__gt=5)
jim.friends.exclude(age__lt=18) # negated
match rels with properties then filter on node properties
jim.friends.match(since__gt=yesterday()).filter(age__gt=5)
jim.friends.match(since__lt=year()).car.match(**kwargs).filter(model="")
# users older than 18 who own a car made over 2 years ago but don't have an address
Users.filter(age__gt=18).has(
car=Car.filter(manufactured__lt=two_years()),
address=False)
# friends that own a car with a trailer
me.friends.all().car.all().has(trailer=True)
Users.filter(age__gt=18).has(car=peugot306)
Issues:
- multi type relationships - solution: disable chaining on multi type relationships.
- how to return multiple types of node