[storm] data separation

Johan Rydberg johan.rydberg at edgeware.tv
Tue Jan 27 18:30:49 GMT 2009


I'm experimenting a bit with storm, and for the sake of data separation
I created three different tables, all sharing the same unique primary
key.  See the example below.

First of all, why is foo.state None before the add?  Will store.add(foo)
also att foo.state and foo.private? I'm under that impression because of
the tutorial.

Lastly, is this pattern supposed to work? :)  I'm not very familiar with
database design.  Can I have two model classes refering to the same
table?


from storm.locals import *

class FooPrivate(object):
     __storm_table__ = 'foo_private'
     id = Int(primary=True)

class FooState(object):
     __storm_table__ = 'foo_state'
     id = Int(primary=True)

class Foo(object):
     __storm_table__ = 'foo'
     id = Int(primary=True)

     private = Reference(id, FooPrivate.id)
     state = Reference(id, FooState.id)

db = create_database("sqlite:")
store = Store(db)
store.execute("CREATE TABLE foo (id INTEGER PRIMARY KEY)")
store.execute("CREATE TABLE foo_state (id INTEGER PRIMARY KEY)")
store.execute("CREATE TABLE foo_private (id INTEGER PRIMARY KEY)")

foo = Foo()
foo.state = FooState()
foo.private = FooPrivate()

print foo
print foo.state         # None?
print foo.private

store.add(foo)
store.flush()
print foo.id
print foo.state.id
print foo.private.id






More information about the storm mailing list