Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changes
1.3 (unreleased)
----------------

- Nothing changed yet.
* ``.datamanager.register()`` now returns the ``ZopeTransactionEvents``
instance which was used to register the events. This allows to change its
parameters afterwards.
(`#40 <https://github.com/zopefoundation/zope.sqlalchemy/pull/40>`_)


1.2 (2019-10-17)
Expand Down
3 changes: 3 additions & 0 deletions src/zope/sqlalchemy/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ same session. At present there are no users in the database.

>>> session = Session()
>>> register(session)
<zope.sqlalchemy.datamanager.ZopeTransactionEvents object at ...>
>>> session.query(User).all()
[]

Expand Down Expand Up @@ -169,6 +170,7 @@ session in the 'changed' state initially.

>>> Session.remove()
>>> register(Session, 'changed')
<zope.sqlalchemy.datamanager.ZopeTransactionEvents object at ...>
>>> session = Session()
>>> conn = session.connection()
>>> conn.execute(users.update(users.c.name=='ben'), name='bob')
Expand Down Expand Up @@ -197,6 +199,7 @@ in test suites) you can specify to keep a session when registering the events:
>>> Session = scoped_session(sessionmaker(bind=engine,
... twophase=TEST_TWOPHASE))
>>> register(Session, keep_session=True)
<zope.sqlalchemy.datamanager.ZopeTransactionEvents object at ...>
>>> session = Session()
>>> bob = session.query(User).all()[0]
>>> bob.name = 'bobby'
Expand Down
4 changes: 4 additions & 0 deletions src/zope/sqlalchemy/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def register(
Event listening will be specific to the scope of the type of argument
passed, including specificity to its subclass as well as its identity.

It returns the instance of ZopeTransactionEvents those methods where used
to register the event listeners.

"""
from sqlalchemy import event

Expand All @@ -323,3 +326,4 @@ def register(
event.listen(session, "after_bulk_update", ext.after_bulk_update)
event.listen(session, "after_bulk_delete", ext.after_bulk_delete)
event.listen(session, "before_commit", ext.before_commit)
return ext