[storm] Storm, sqlite, and lists
Jamu Kakar
jamshed.kakar at canonical.com
Fri Jul 27 18:59:38 BST 2007
Hi,
Jamu Kakar wrote:
> Nope, you don't need to commit for this case. For the most part, you
> can just access the attribute and Storm will auto-flush the changes to
> the database (without actually committing the changes). For example,
> the following should work:
It turns out the code I provided previously (that I didn't test)
doesn't actually work. Nor do my expectations of Storm regarding
auto-flushing and auto-adding in that particular case. Sorry for not
being more careful with my answers.
Below is a script with the previous example implemented. It produces
the following output when it runs:
$ python add-and-flush-example.py
None None
1 1
Thanks,
J.
from storm.locals import create_database, Storm, Store, Int, Unicode
class Account(Storm):
__storm_table__ = "account"
id = Int(primary=True)
owner_id = Int(default=0)
class Person(Storm):
__storm_table__ = "person"
id = Int(primary=True)
name = Unicode()
def __init__(self, name):
self.name = name
database = create_database("sqlite:")
store = Store(database)
store.execute("CREATE TABLE person ("
" id INTEGER PRIMARY KEY,"
" name VARCHAR)",
noresult=True)
store.execute("CREATE TABLE account ("
" id INTEGER PRIMARY KEY,"
" owner_id INTEGER)",
noresult=True)
account = store.add(Account())
account.owner = store.add(Person("Bob"))
print account.id, account.owner.id
store.commit()
print account.id, account.owner.id
More information about the storm
mailing list