summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/asyncio/engine.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2023-04-07 20:12:04 +0200
committerFederico Caselli <cfederico87@gmail.com>2023-04-12 22:30:35 +0200
commit541ada1bad609b7f2052d0b02214387e242c6cc5 (patch)
tree0054fff02624e2cb461fee4d5687031d5ebf7f8c /lib/sqlalchemy/ext/asyncio/engine.py
parent107ec58bdfbcbb09f40d92590f8197ffa683a925 (diff)
downloadsqlalchemy-541ada1bad609b7f2052d0b02214387e242c6cc5.tar.gz
Add pool creation functions
Added :func:`_sa.create_pool_from_url` and :func:`_asyncio.create_async_pool_from_url` to create a :class:`_pool.Pool` instance from an input url passed as string or :class:`_sa.URL`. Fixes: #9613 Change-Id: Icd8aa3f2849e6fd1bc5341114f3ef8d216a2c543
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/engine.py')
-rw-r--r--lib/sqlalchemy/ext/asyncio/engine.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py
index 325c58bda..440cf834d 100644
--- a/lib/sqlalchemy/ext/asyncio/engine.py
+++ b/lib/sqlalchemy/ext/asyncio/engine.py
@@ -35,6 +35,7 @@ from ... import inspection
from ... import util
from ...engine import Connection
from ...engine import create_engine as _create_engine
+from ...engine import create_pool_from_url as _create_pool_from_url
from ...engine import Engine
from ...engine.base import NestedTransaction
from ...engine.base import Transaction
@@ -80,7 +81,6 @@ def create_async_engine(url: Union[str, URL], **kw: Any) -> AsyncEngine:
"use the connection.stream() method for an async "
"streaming result set"
)
- kw["future"] = True
kw["_is_async"] = True
sync_engine = _create_engine(url, **kw)
return AsyncEngine(sync_engine)
@@ -111,6 +111,21 @@ def async_engine_from_config(
return create_async_engine(url, **options)
+def create_async_pool_from_url(url: Union[str, URL], **kwargs: Any) -> Pool:
+ """Create a new async engine instance.
+
+ Arguments passed to :func:`_asyncio.create_async_pool_from_url` are mostly
+ identical to those passed to the :func:`_sa.create_pool_from_url` function.
+ The specified dialect must be an asyncio-compatible dialect
+ such as :ref:`dialect-postgresql-asyncpg`.
+
+ .. versionadded:: 2.0.10
+
+ """
+ kwargs["_is_async"] = True
+ return _create_pool_from_url(url, **kwargs)
+
+
class AsyncConnectable:
__slots__ = "_slots_dispatch", "__weakref__"