5
from storm.locals import *
7
database = create_database("sqlite:///temp.sqlite")
8
store = Store(database)
11
__storm_table__ = "person"
12
id = Int(primary=True)
15
class Company(object):
16
__storm_table__ = "company"
17
id = Int(primary=True)
20
def __init__(self, name):
23
class Employee(Person):
24
__storm_table__ = "employee"
26
company = Reference(company_id, Company.id)
28
def __init__(self, name):
33
joe.name = u"Joe Johnes"
34
print "%r, %r" % (joe.id, joe.name)
37
print "%r, %r" % (joe.id, joe.name)
38
print Store.of(joe) is store
39
print Store.of(Person()) is None
41
person = store.find(Person, Person.name == u"Joe Johnes").one()
43
print "%r, %r" % (person.id, person.name)
48
mary.name = u"Mary MArgaret"
51
print "%r, %r" % (mary.id, mary.name)
53
print "%r, %r" % (mary.id, mary.name)
57
ben = store.add(Employee(u"Ben Bill"))
58
print "%r, %r, %r" % (ben.id, ben.name, ben.company_id)
62
print "%r, %r" % (ben.company_id, ben.company.name)
64
sweets = store.add(Company(u"Sweets Inc."))
69
print ben.company.name
70
print "ben esta en sweets?"
71
print ben.company is sweets
76
circus = Company(u"Circus Inc.")
77
print "%r, %r" % (mary.id, mary.name)
79
print "%r, %r" % (mary.id, mary.name)
83
store.execute("CREATE TABLE person "
84
"(id INTEGER PRIMARY KEY, name VARCHAR)")
85
store.execute("CREATE TABLE company "
86
"(id INTEGER PRIMARY KEY, name VARCHAR)", noresult=True)
87
store.execute("CREATE TABLE employee "
88
"(id INTEGER PRIMARY KEY, name VARCHAR, company_id INTEGER)",
96
if __name__ == "__main__":