Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapcloud/434bbc8cc5bd81e8e0d1c478f0224ab7 to your computer and use it in GitHub Desktop.
Save mapcloud/434bbc8cc5bd81e8e0d1c478f0224ab7 to your computer and use it in GitHub Desktop.
Define and use custom step in Gremlin via pyorient.
#!/usr/bin/env python
"""
Define and use custom step in Gremlin via pyorient.
"""
from pyorient.ogm import Graph, Config
from pyorient.ogm.declarative import declarative_node, declarative_relationship
from pyorient.ogm.property import String
Node = declarative_node()
Rel = declarative_relationship()
class TestNode(Node):
element_type = 'testnode'
element_plural = 'testnodes'
mystr = String(nullable=False, unique=False, indexed=True)
class TestRel(Rel):
label = 'testrel'
if __name__ == '__main__':
g = Graph(Config('localhost', 2424, 'admin', 'admin', 'ogm',
storage='memory', initial_drop=True))
g.create_all(Node.registry)
g.create_all(Rel.registry)
foo = g.testnodes.create(mystr='foo')
bar = g.testnodes.create(mystr='bar')
baz = g.testnodes.create(mystr='baz')
g.testrel.create(foo, bar)
g.testrel.create(bar, baz)
g.testrel.create(baz, foo)
g.client.gremlin("Gremlin.defineStep('mystep', [Vertex, Pipe], {_().out.out});")
result = g.gremlin("g.V.has('mystr', 'foo').mystep")
assert result[0].mystr == 'baz'
result = g.gremlin("g.V.has('mystr', 'bar').mystep")
assert result[0].mystr == 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment