Assorted utility functions to support working with SQLAlchemy.
Project description
Assorted utility functions to support working with SQLAlchemy.
Function auto_session(func)
Decorator to run a function in a session is not presupplied.
Class ORM
A convenience base class for an ORM class.
This defines a .Base
attribute which is a new DeclarativeBase
and provides various Session related convenience methods.
Subclasses must define their private ._Session
factory in
their own __init__
, for example:
self._Session = sessionmaker(bind=engine)
Function with_session(func, *a, orm=None, session=None, **kw)
Call func(*a,session=session,**kw)
, creating a session if required.
This is the inner mechanism of @auto_session
and
ORM.auto_session_method
.
Parameters:
func
: the function to calla
: the positional parametersorm
: optional ORM class with a.session()
context manager methodsession
: optional existing ORM session
One of orm
or session
must be not None
; if session
is None
then one is made from orm.session()
and used as
a context manager. The session
is also passed to func
as
the keyword parameter session
to support nested calls.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cs.sqlalchemy_utils-20190319.1.tar.gz
.
File metadata
- Download URL: cs.sqlalchemy_utils-20190319.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d5a2fde75397ff9fa26d78721f156eda4327f92802722d8d66e7fb0678858e9 |
|
MD5 | 36ebb8abbcb858e673c89ea2bde6c54f |
|
BLAKE2b-256 | 0f68bb95de4cec9f8d040dcdfb692a7136e6f9d0636d19df1f7bdf4e2e84e7bd |