summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2016-11-03 12:03:13 +0200
committerRoman Podoliaka <rpodolyaka@mirantis.com>2016-12-12 10:38:06 +0000
commit181109678bf2667efc37466f67cfd9a60ba0962a (patch)
treeffd55ec740b0ff09e97b832925fa771b2aeeb919
parentd7993bab9dce0efc4a31ee3d31bda0aef5cf6b09 (diff)
downloadoslo-db-181109678bf2667efc37466f67cfd9a60ba0962a.tar.gz
docs: mention that it's possible to use Connection directly
Sometimes people just do not need the ORM part and a Session at all. Mention the fact, that it's possible to ask for a Connection in enginefacade. Change-Id: I7a135be7149cd3fa140e0268fea5a17f23f402b2
-rw-r--r--doc/source/usage.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/source/usage.rst b/doc/source/usage.rst
index 448afaa..1b2d996 100644
--- a/doc/source/usage.rst
+++ b/doc/source/usage.rst
@@ -75,6 +75,21 @@ decorator. Each function must receive the context argument:
results = some_reader_api_function(context)
some_writer_api_function(context, 5, 10)
+
+``connection`` modifier can be used when a :class:`.Session` object is not
+needed, e.g. when `SQLAlchemy Core <http://docs.sqlalchemy.org/en/latest/core/>`_
+is preferred:
+
+.. code:: python
+
+ @enginefacade.reader.connection
+ def _refresh_from_db(context, cache):
+ sel = sa.select([table.c.id, table.c.name])
+ res = context.connection.execute(sel).fetchall()
+ cache.id_cache = {r[1]: r[0] for r in res}
+ cache.str_cache = {r[0]: r[1] for r in res}
+
+
.. note:: The ``context.session`` and ``context.connection`` attributes
must be accessed within the scope of an appropriate writer/reader block
(either the decorator or contextmanager approach). An AttributeError is