diff options
author | Nils Philippsen <nils@tiptoe.de> | 2021-11-13 11:11:32 -0500 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2021-12-10 17:20:31 +0100 |
commit | 98b1650efce79ae6d304eb08047890ef8ae89df1 (patch) | |
tree | 290ad5959858679b1b810a047fc54b4eafc070d4 /lib/sqlalchemy/ext/asyncio | |
parent | 9d837b02b5eb42385281b88d09fe2aeea0376ca9 (diff) | |
download | sqlalchemy-98b1650efce79ae6d304eb08047890ef8ae89df1.tar.gz |
Add async_engine_from_config()
Added :func:`_asyncio.async_engine_config` function to create
an async engine from a configuration dict. This otherwise
behaves the same as :func:`_sa.engine_from_config`.
Fixes: #7301
Closes: #7302
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7302
Pull-request-sha: c7c758833b6c37b7509b8c5bed4f26ac0ccc0395
Change-Id: I64feadf95b5015c24fe0fa0dbae6755b72d1713e
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/__init__.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/engine.py | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/__init__.py b/lib/sqlalchemy/ext/asyncio/__init__.py index ac3b905c6..031039713 100644 --- a/lib/sqlalchemy/ext/asyncio/__init__.py +++ b/lib/sqlalchemy/ext/asyncio/__init__.py @@ -5,6 +5,7 @@ # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php +from .engine import async_engine_from_config from .engine import AsyncConnection from .engine import AsyncEngine from .engine import AsyncTransaction diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index 67d944b9c..476d5515c 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -42,6 +42,29 @@ def create_async_engine(*arg, **kw): return AsyncEngine(sync_engine) +def async_engine_from_config(configuration, prefix="sqlalchemy.", **kwargs): + """Create a new AsyncEngine instance using a configuration dictionary. + + This function is analogous to the :func:`_sa.engine_from_config` function + in SQLAlchemy Core, except that the requested dialect must be an + asyncio-compatible dialect such as :ref:`dialect-postgresql-asyncpg`. + The argument signature of the function is identical to that + of :func:`_sa.engine_from_config`. + + .. versionadded:: 1.4.29 + + """ + options = { + key[len(prefix) :]: value + for key, value in configuration.items() + if key.startswith(prefix) + } + options["_coerce_config"] = True + options.update(kwargs) + url = options.pop("url") + return create_async_engine(url, **options) + + class AsyncConnectable: __slots__ = "_slots_dispatch", "__weakref__" |