public
Last active

Bulbs 0.3 Neo4j Server Example

  • Download Gist
bulbs03_example.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
from bulbs.config import Config
from bulbs.gremlin import Gremlin
from bulbs.model import Node, NodeProxy
from bulbs.property import String, Integer
from bulbs.element import Vertex, VertexProxy, EdgeProxy, Edge
from bulbs.neo4jserver import Neo4jResource, NEO4J_URI, \
VertexIndexProxy, EdgeIndexProxy, ExactIndex
 
class Person(Node):
 
element_type = "person"
name = String(nullable=False)
age = Integer()
class Whybase(object):
 
def __init__(self):
self.config = Config(NEO4J_URI)
self.resource = Neo4jResource(self.config)
 
self.gremlin = Gremlin(self.resource)
self.indicesV = VertexIndexProxy(ExactIndex,self.resource)
self.indicesE = EdgeIndexProxy(ExactIndex,self.resource)
self.vertices = VertexProxy(Vertex,self.resource)
self.vertices.index = self.indicesV.get_or_create("vertices")
self.edges = EdgeProxy(Edge,self.resource)
self.edges.index = self.indicesE.get_or_create("edges")
 
self.people = NodeProxy(Person,self.resource)
self.people.index = self.indicesV.get_or_create("person")
 
whybase = Whybase()
james = whybase.people.create(name="James Thornton",age=34)
 
print james.eid, james.name, james.age
 
james.name = "James William Thornton"
james.city = "Dallas"
james.save()
 
print james.eid, james.name, james.age, james.city

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.