diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-05 20:55:33 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-05 20:55:33 +0000 |
commit | 9629838f7dceab972c70938b58b7ec1ff44739e2 (patch) | |
tree | 3d9ce7f2f4bd3d06e0e1f581057f5773ccb07a1f /examples/vertical/vertical.py | |
parent | 9e4052dc8be2451d1c48bb059da150ce41ddc86f (diff) | |
download | sqlalchemy-9629838f7dceab972c70938b58b7ec1ff44739e2.tar.gz |
- fixed wrong varname in session exception throw
- fixed vertical example to just use a scoped session
Diffstat (limited to 'examples/vertical/vertical.py')
-rw-r--r-- | examples/vertical/vertical.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/examples/vertical/vertical.py b/examples/vertical/vertical.py index e3b48c336..225beeffe 100644 --- a/examples/vertical/vertical.py +++ b/examples/vertical/vertical.py @@ -10,6 +10,8 @@ import datetime e = MetaData('sqlite://') e.bind.echo = True +Session = scoped_session(sessionmaker(transactional=True)) + # this table represents Entity objects. each Entity gets a row in this table, # with a primary key and a title. entities = Table('entities', e, @@ -84,10 +86,7 @@ class EntityValue(object): the value to the underlying datatype of its EntityField.""" def __init__(self, key=None, value=None): if key is not None: - sess = create_session() - self.field = sess.query(EntityField).get_by(name=key) or EntityField(key) - # close the session, which will make a loaded EntityField a detached instance - sess.close() + self.field = Session.query(EntityField).filter(EntityField.name==key).first() or EntityField(key) if self.field.datatype is None: if isinstance(value, int): self.field.datatype = 'int' @@ -123,7 +122,7 @@ mapper(Entity, entities, properties = { # create two entities. the objects can be used about as regularly as # any object can. -session = create_session() +session = Session() entity = Entity() entity.title = 'this is the first entity' entity.name = 'this is the name' |