From 5fb0138a3220161703e6ab1087319a669d14e7f4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 Jul 2020 12:21:36 -0400 Subject: 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 --- lib/sqlalchemy/sql/__init__.py | 1 + lib/sqlalchemy/sql/sqltypes.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/__init__.py b/lib/sqlalchemy/sql/__init__.py index 2fe6f35d2..8f6dc8e72 100644 --- a/lib/sqlalchemy/sql/__init__.py +++ b/lib/sqlalchemy/sql/__init__.py @@ -5,6 +5,7 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php +from .base import Executable # noqa from .compiler import COLLECT_CARTESIAN_PRODUCTS # noqa from .compiler import FROM_LINTING # noqa from .compiler import NO_LINTING # noqa diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 186f885d8..64663a6b0 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -2316,6 +2316,22 @@ class JSON(Indexable, TypeEngine): """ + class JSONIntIndexType(JSONIndexType): + """Placeholder for the datatype of a JSON index value. + + This allows execution-time processing of JSON index values + for special syntaxes. + + """ + + class JSONStrIndexType(JSONIndexType): + """Placeholder for the datatype of a JSON index value. + + This allows execution-time processing of JSON index values + for special syntaxes. + + """ + class JSONPathType(JSONElementType): """Placeholder type for JSON path operations. @@ -2346,7 +2362,9 @@ class JSON(Indexable, TypeEngine): index, expr=self.expr, operator=operators.json_getitem_op, - bindparam_type=JSON.JSONIndexType, + bindparam_type=JSON.JSONIntIndexType + if isinstance(index, int) + else JSON.JSONStrIndexType, ) operator = operators.json_getitem_op -- cgit v1.2.1