diff options
author | Michael Trier <mtrier@gmail.com> | 2009-03-31 22:31:08 +0000 |
---|---|---|
committer | Michael Trier <mtrier@gmail.com> | 2009-03-31 22:31:08 +0000 |
commit | 6010afb28f95c7050ca48ddd2e6f65ca6cbae5a1 (patch) | |
tree | 46259c03c209a89702c32c939c8ea035edee9425 /examples/pickle/custom_pickler.py | |
parent | 832ea82fefa366f4717e889511f66ecfce3313de (diff) | |
download | sqlalchemy-6010afb28f95c7050ca48ddd2e6f65ca6cbae5a1.tar.gz |
Lots of fixes to the code examples to specify imports explicitly.
Explicit imports make it easier for users to understand the examples.
Additionally a lot of the examples were fixed to work with the changes in the
0.5.x code base. One small correction to the Case expression. Thanks a bunch
to Adam Lowry! Fixes #717.
Diffstat (limited to 'examples/pickle/custom_pickler.py')
-rw-r--r-- | examples/pickle/custom_pickler.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/examples/pickle/custom_pickler.py b/examples/pickle/custom_pickler.py index 1c88c88e8..79a8b3fa3 100644 --- a/examples/pickle/custom_pickler.py +++ b/examples/pickle/custom_pickler.py @@ -1,7 +1,8 @@ """illustrates one way to use a custom pickler that is session-aware.""" -from sqlalchemy import * -from sqlalchemy.orm import * +from sqlalchemy import MetaData, Table, Column, Integer, String, PickleType +from sqlalchemy.orm import (mapper, create_session, MapperExtension, + class_mapper, EXT_CONTINUE) from sqlalchemy.orm.session import object_session from cStringIO import StringIO from pickle import Pickler, Unpickler @@ -28,7 +29,7 @@ class MyPickler(object): if getattr(obj, "id", None) is None: sess = MyPickler.sessions.current newsess = create_session(bind=sess.connection(class_mapper(Bar))) - newsess.save(obj) + newsess.add(obj) newsess.flush() key = "%s:%s" % (type(obj).__name__, obj.id) return key @@ -74,9 +75,9 @@ mapper(Bar, bar_table) sess = create_session() f = Foo() f.bar = Bar('some bar') -sess.save(f) +sess.add(f) sess.flush() -sess.clear() +sess.expunge_all() del MyPickler.sessions.current |