public
Created

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
# Bulbs 0.3 Neo4j Server Example
# by James Thornton (http://jamesthornton.com)
 
from bulbs.neo4jserver import Graph
from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime
 
class Person(Node):
 
element_type = "person"
 
name = String(nullable=False)
age = Integer()
 
 
class Knows(Relationship):
 
label = "knows"
 
timestamp = DateTime(default=current_datetime, nullable=False)
 
g = Graph()
g.add_proxy("people", Person)
g.add_proxy("knows", Knows)
 
james = g.people.create(name="James",age=34)
julie = g.people.create(name="Julie")
 
knows = g.knows.create(james,julie)
 
print type(james), james.eid, james.element_type, james.name, james.age
 
james.name = "James Thornton"
james.city = "Dallas"
james.save()
 
james2 = g.people.get(james.eid)
print james2.city
 
friends = james.outV('knows')
print list(friends)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.