Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #11 from daltonmatos/develop
Browse files Browse the repository at this point in the history
Release 0.5
  • Loading branch information
daltonmatos committed Mar 29, 2016
2 parents d362383 + 490d525 commit 99bfcb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

build/
dist/
.eggs/
*egg-info/
.idea/
.coverage
34 changes: 20 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,36 @@ managed

This is the basic context manager and it will commit and close your session automatically, at the end of the ``with`` block.

::
.. code-block:: python
with managed(MySessionClass) as session:
# Do what you need with your session
# Here the session is already closed and commited
with managed(MySessionClass) as session:
# Do what you need with your session
# Here the session is already closed and commited
If you raise any exception inside the ``with`` block, the session will be rolled back and the exception re-raised.

To avoid having all of the function body inside the ``with`` block, ``managed`` functions as a context manager as well.

::
.. code-block:: python
@managed(MySessionClass)
def foo(session, *args, **kwargs):
# Do what you need with your session
pass
@managed(MySessionClass)
def foo(session, *args, **kwargs):
# Do what you need with your session
pass


# call as if the session didn't exist:
foo(2, a='b')
# call as if the session didn't exist:
foo(2, a='b')
The session is opened every time the function is called and closed whenever it returns or raises an exception. Autommit and rollback rules work as normal.

Additional options
^^^^^^^^^^^^^^^^^^

* ``auto_flush``: Sets the autoflush option on the SQLAlchemy session, defaults fo ``False``
``auto_flush``: Sets the autoflush option on the SQLAlchemy session, defaults fo ``False``

Executing tests
^^^^^^^^^^^^^^^

.. code-block:: shell
$ python setup.py test
2 changes: 1 addition & 1 deletion alchemytools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@


__version__ = '0.4'
__version__ = '0.5'
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
author_email='[email protected]',
url='https://github.com/daltonmatos/alchemytools',
packages=find_packages(),
install_requires=['SQLAlchemy >=0.7.8, <=0.9.2'],
install_requires=['SQLAlchemy >=0.7.8, <=1.0.12'],
tests_require=['mock==1.3.0'],
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
Expand Down

0 comments on commit 99bfcb7

Please sign in to comment.