summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-01-04 16:29:42 +0000
committerGerrit Code Review <review@openstack.org>2017-01-04 16:29:43 +0000
commit5095c7c16c90df3fc6d3eb1ee31b6ac291b77df6 (patch)
tree81efc84c32c1473e3a157d37e22df7182407d10d
parentceba339b6aa442d2bcca09e48957fbdfa970a26c (diff)
parent181109678bf2667efc37466f67cfd9a60ba0962a (diff)
downloadoslo-db-5095c7c16c90df3fc6d3eb1ee31b6ac291b77df6.tar.gz
Merge "docs: mention that it's possible to use Connection directly"4.17.0
-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