]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use AsyncAdaptedQueuePool in aiosqlite
authorChristophe Bornet <cbornet@hotmail.com>
Thu, 30 Jan 2025 13:05:20 +0000 (14:05 +0100)
committerChristophe Bornet <cbornet@hotmail.com>
Thu, 30 Jan 2025 13:05:20 +0000 (14:05 +0100)
This ensures consistency with pysqlite and least surprise when
migrating from sync to async

lib/sqlalchemy/dialects/sqlite/aiosqlite.py

index 60a49db38c391f595ccc5c004490ed20d5b23c07..37f44bf121893d6e4190ee31e894de05fadb6db6 100644 (file)
@@ -78,6 +78,28 @@ The solution is similar to :ref:`pysqlite_serializable`. This is achieved by the
    with the SQLite driver,
    as this function necessarily will also alter the ".isolation_level" setting.
 
+.. _aiosqlite_pooling:
+
+Pooling Behavior
+----------------
+
+The SQLAlchemy ``aiosqlite`` DBAPI establishes the connection pool differently
+based on the kind of SQLite database that's requested:
+
+* When a ``:memory:`` SQLite database is specified, the dialect by default
+  will use :class:`.StaticPool`. This pool maintains a single
+  connection, so that all access to the engine
+  use the same ``:memory:`` database.
+* When a file-based database is specified, the dialect will use
+  :class:`.AsyncAdaptedQueuePool` as the source of connections.
+
+  .. versionchanged:: 2.0.37
+
+    SQLite file database engines now use :class:`.AsyncAdaptedQueuePool` by default.
+    Previously, :class:`.NullPool` were used.  The :class:`.NullPool` class
+    may be used by specifying it via the
+    :paramref:`_sa.create_engine.poolclass` parameter.
+
 """  # noqa
 
 import asyncio
@@ -235,7 +257,7 @@ class SQLiteDialect_aiosqlite(SQLiteDialect_pysqlite):
     @classmethod
     def get_pool_class(cls, url):
         if cls._is_url_file_db(url):
-            return pool.NullPool
+            return pool.AsyncAdaptedQueuePool
         else:
             return pool.StaticPool