diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-22 19:03:06 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-22 19:03:06 -0500 |
| commit | 82e4bc2f52f2d420842819d0ffe548ca968bf54e (patch) | |
| tree | 0edb77b8bff7fe074dd0be4faafd551648901d43 /examples/versioning/__init__.py | |
| parent | 79cf693b05bdd31b2397116f3092e3be9df6baa2 (diff) | |
| download | sqlalchemy-82e4bc2f52f2d420842819d0ffe548ca968bf54e.tar.gz | |
- [feature] Simplified the versioning example
a bit to use a declarative mixin as well
as an event listener, instead of a metaclass +
SessionExtension. [ticket:2313]
Diffstat (limited to 'examples/versioning/__init__.py')
| -rw-r--r-- | examples/versioning/__init__.py | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/examples/versioning/__init__.py b/examples/versioning/__init__.py index 61b8f13c6..990900940 100644 --- a/examples/versioning/__init__.py +++ b/examples/versioning/__init__.py @@ -13,12 +13,11 @@ be run via nose:: A fragment of example usage, using declarative:: - from history_meta import VersionedMeta, VersionedListener + from history_meta import Versioned, versioned_session - Base = declarative_base(metaclass=VersionedMeta, bind=engine) - Session = sessionmaker(extension=VersionedListener()) + Base = declarative_base() - class SomeClass(Base): + class SomeClass(Versioned, Base): __tablename__ = 'sometable' id = Column(Integer, primary_key=True) @@ -27,6 +26,9 @@ A fragment of example usage, using declarative:: def __eq__(self, other): assert type(other) is SomeClass and other.id == self.id + Session = sessionmaker(bind=engine) + versioned_session(Session) + sess = Session() sc = SomeClass(name='sc1') sess.add(sc) @@ -44,26 +46,8 @@ A fragment of example usage, using declarative:: all() \\ == [SomeClassHistory(version=1, name='sc1')] -To apply ``VersionedMeta`` to a subset of classes (probably more typical), the -metaclass can be applied on a per-class basis:: - - from history_meta import VersionedMeta, VersionedListener - - Base = declarative_base(bind=engine) - - class SomeClass(Base): - __tablename__ = 'sometable' - - # ... - - class SomeVersionedClass(Base): - __metaclass__ = VersionedMeta - __tablename__ = 'someothertable' - - # ... - -The ``VersionedMeta`` is a declarative metaclass - to use the extension with -plain mappers, the ``_history_mapper`` function can be applied:: +The ``Versioned`` mixin is designed to work with declarative. To use the extension with +classical mappers, the ``_history_mapper`` function can be applied:: from history_meta import _history_mapper |
