#Listing vertex
from goblin import DriverRemoteConnection
from goblin import Graph
async def go(loop):
remote_connection = await DriverRemoteConnection.open(
'http://localhost:8182/gremlin', 'g')
g = Graph().traversal().withRemote(remote_connection)
vertices = await g.V().toList()
await remote_connection.close()
return vertices
#Adding a vertex
from goblin import Goblin, element, properties
class Person(element.Vertex):
__label__ = 'person'
name = properties.Property(properties.String)
age = properties.Property(properties.Integer)
app = Goblin.open(
event_loop,
hosts=['localhost'],
port=8182)
session = await app.session()
jon = Person()
jon.name = 'jonathan'
jon.age = 38
session.save(jon)
await app.close()
#Property defaults
from gremlin_python.process.traversal import Cardinality
class Person(goblin.Vertex):
name = goblin.Property(goblin.String, default='John Doe')
#Metaproperties
class HistoricalName(goblin.VertexProperty):
notes = goblin.Property(goblin.String)
class City(goblin.Vertex):
name = goblin.Property(goblin.String)
population = goblin.Property(goblin.Integer)
historical_name = HistoricalName(
goblin.String, card=Cardinality.list_)
montreal = City()
montreal.historical_name = ['Ville-Marie']
montreal.historical_name('Ville-Marie').notes = 'Changed in 1705'
#Optimistic Creation Locking
import goblin
from goblin.element import ImmutableMode, LockingMode
class Person(goblin.Vertex):
def __init__(self):
return super().__init__()
self.__locking__ = LockingMode.OPTIMISTIC_LOCKING
name = kobalos.Property(kobalos.String)
name = "Jeffrey Phillips Freeman"
jeff = Person()
jeff.name = name
session.add(jeff)
conflicts_query = (__.
V().
hasLabel(Person.__label__).
has("name", name).
hasNot('dirty').
count().
is_(0))
await session.flush(conflicts_query)