From 4a7d2cb52093b987a7682cc927737f21c03d874e Mon Sep 17 00:00:00 2001 From: TimothyAllman <166746823+TimothyAllman@users.noreply.github.com> Date: Tue, 23 Jun 2026 20:53:03 +0200 Subject: [PATCH 1/2] add boolean input param to enable WAL mode --- piccolo/engine/sqlite.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/piccolo/engine/sqlite.py b/piccolo/engine/sqlite.py index 2b1840c58..aafd3360f 100644 --- a/piccolo/engine/sqlite.py +++ b/piccolo/engine/sqlite.py @@ -590,6 +590,7 @@ def __init__( path: str = "piccolo.sqlite", log_queries: bool = False, log_responses: bool = False, + enable_wal_mode: bool = False, **connection_kwargs, ) -> None: """ @@ -618,6 +619,7 @@ def __init__( self.log_queries = log_queries self.log_responses = log_responses + self.enable_wal_mode = enable_wal_mode self.connection_kwargs = { **default_connection_kwargs, **connection_kwargs, @@ -696,6 +698,10 @@ async def get_connection(self) -> Connection: connection = await aiosqlite.connect(**self.connection_kwargs) connection.row_factory = dict_factory # type: ignore await connection.execute("PRAGMA foreign_keys = 1") + + if self.enable_wal_mode: + await connection.execute("PRAGMA journal_mode = WAL") + return connection ########################################################################### @@ -724,6 +730,9 @@ async def _run_in_new_connection( args = [] async with aiosqlite.connect(**self.connection_kwargs) as connection: await connection.execute("PRAGMA foreign_keys = 1") + + if self.enable_wal_mode: + await connection.execute("PRAGMA journal_mode = WAL") connection.row_factory = dict_factory # type: ignore async with connection.execute(query, args) as cursor: @@ -753,6 +762,9 @@ async def _run_in_existing_connection( args = [] await connection.execute("PRAGMA foreign_keys = 1") + if self.enable_wal_mode: + await connection.execute("PRAGMA journal_mode = WAL") + connection.row_factory = dict_factory async with connection.execute(query, args) as cursor: response = await cursor.fetchall() From ad1d3f0b425ce8eb04b9342493a14388ae2850f9 Mon Sep 17 00:00:00 2001 From: TimothyAllman <166746823+TimothyAllman@users.noreply.github.com> Date: Tue, 23 Jun 2026 21:06:55 +0200 Subject: [PATCH 2/2] add docstring for new param --- piccolo/engine/sqlite.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/piccolo/engine/sqlite.py b/piccolo/engine/sqlite.py index aafd3360f..cf5a72d4a 100644 --- a/piccolo/engine/sqlite.py +++ b/piccolo/engine/sqlite.py @@ -603,6 +603,9 @@ def __init__( :param log_responses: If ``True``, the raw response from each query is printed out. Useful for debugging. + :param enable_wal_mode: + If ``True``, set the journal mode to write ahead logging (WAL) + i.e. execute `PRAGMA journal_mode = WAL` when returning the db connection. :param connection_kwargs: These are passed directly to the database adapter. We recommend setting ``timeout`` if you expect your application to process a @@ -764,7 +767,7 @@ async def _run_in_existing_connection( if self.enable_wal_mode: await connection.execute("PRAGMA journal_mode = WAL") - + connection.row_factory = dict_factory async with connection.execute(query, args) as cursor: response = await cursor.fetchall()