summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/future
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-07-04 12:21:36 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-08-13 18:41:53 -0400
commit5fb0138a3220161703e6ab1087319a669d14e7f4 (patch)
tree25d006b30830ce6bc71f7a69bed9b570e1ae9654 /lib/sqlalchemy/future
parentcd03b8f0cecbf72ecd6c99c4d3a6338c8278b40d (diff)
downloadsqlalchemy-5fb0138a3220161703e6ab1087319a669d14e7f4.tar.gz
Implement rudimentary asyncio support w/ asyncpg
Using the approach introduced at https://gist.github.com/zzzeek/6287e28054d3baddc07fa21a7227904e We can now create asyncio endpoints that are then handled in "implicit IO" form within the majority of the Core internals. Then coroutines are re-exposed at the point at which we call into asyncpg methods. Patch includes: * asyncpg dialect * asyncio package * engine, result, ORM session classes * new test fixtures, tests * some work with pep-484 and a short plugin for the pyannotate package, which seems to have so-so results Change-Id: Idbcc0eff72c4cad572914acdd6f40ddb1aef1a7d Fixes: #3414
Diffstat (limited to 'lib/sqlalchemy/future')
-rw-r--r--lib/sqlalchemy/future/__init__.py1
-rw-r--r--lib/sqlalchemy/future/engine.py19
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/future/__init__.py b/lib/sqlalchemy/future/__init__.py
index 37ce46e47..b07b9b040 100644
--- a/lib/sqlalchemy/future/__init__.py
+++ b/lib/sqlalchemy/future/__init__.py
@@ -14,4 +14,5 @@ from .engine import Engine # noqa
from ..sql.selectable import Select # noqa
from ..util.langhelpers import public_factory
+
select = public_factory(Select._create_future_select, ".future.select")
diff --git a/lib/sqlalchemy/future/engine.py b/lib/sqlalchemy/future/engine.py
index d5922daa3..dd72360ed 100644
--- a/lib/sqlalchemy/future/engine.py
+++ b/lib/sqlalchemy/future/engine.py
@@ -359,6 +359,22 @@ class Engine(_LegacyEngine):
execution_options=legacy_engine._execution_options,
)
+ class _trans_ctx(object):
+ def __init__(self, conn):
+ self.conn = conn
+
+ def __enter__(self):
+ self.transaction = self.conn.begin()
+ return self.conn
+
+ def __exit__(self, type_, value, traceback):
+ if type_ is not None:
+ self.transaction.rollback()
+ else:
+ if self.transaction.is_active:
+ self.transaction.commit()
+ self.conn.close()
+
def begin(self):
"""Return a :class:`_future.Connection` object with a transaction
begun.
@@ -381,7 +397,8 @@ class Engine(_LegacyEngine):
:meth:`_future.Connection.begin`
"""
- return super(Engine, self).begin()
+ conn = self.connect()
+ return self._trans_ctx(conn)
def connect(self):
"""Return a new :class:`_future.Connection` object.