From 181109678bf2667efc37466f67cfd9a60ba0962a Mon Sep 17 00:00:00 2001 From: Roman Podoliaka Date: Thu, 3 Nov 2016 12:03:13 +0200 Subject: [PATCH] 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 --- doc/source/usage.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 448afaaf..1b2d9961 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 `_ +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