diff options
| author | J08nY | 2017-06-22 19:12:04 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-22 19:12:04 +0200 |
| commit | 5014e7a75f02f8c707847122ff43b37064247a43 (patch) | |
| tree | 19bda52a1507fa7fe09e051ccee0129aace62d85 /src/mailman_pgp/database | |
| parent | 429234b8db28ed6aadf21a3ccfce7eaf7065be71 (diff) | |
| download | mailman-pgp-5014e7a75f02f8c707847122ff43b37064247a43.tar.gz mailman-pgp-5014e7a75f02f8c707847122ff43b37064247a43.tar.zst mailman-pgp-5014e7a75f02f8c707847122ff43b37064247a43.zip | |
Diffstat (limited to 'src/mailman_pgp/database')
| -rw-r--r-- | src/mailman_pgp/database/__init__.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/mailman_pgp/database/__init__.py b/src/mailman_pgp/database/__init__.py index 950c6b1..bbb7840 100644 --- a/src/mailman_pgp/database/__init__.py +++ b/src/mailman_pgp/database/__init__.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. -"""""" +"""Common database functions and class.""" from contextlib import contextmanager @@ -31,6 +31,8 @@ from mailman_pgp.model.base import Base @public class Database: + """A SQLAlchemy database.""" + def __init__(self): url = config.get('db', 'url') self._url = expand(url, None, mailman_config.paths) @@ -41,12 +43,24 @@ class Database: @property def session(self): + """ + Get a scoped_session. + + :return: A scoped session. + :rtype: scoped_session + """ return self._scoped_session() @public @contextmanager def transaction(): + """ + A transaction context manager. + + :return: A session for convenience. + :rtype: scoped_session + """ try: yield config.db.session except: @@ -58,4 +72,11 @@ def transaction(): @public def query(cls): + """ + A query helper. + + :param cls: Class to query. + :return: A query on the class. + :rtype: sqlalchemy.orm.query.Query + """ return config.db.session.query(cls) |
