|
9 | 9 | from dataclasses import dataclass |
10 | 10 | from decimal import Decimal |
11 | 11 |
|
12 | | -from aiosqlite import Connection, Cursor, connect |
13 | | - |
14 | 12 | from piccolo.engine.base import Batch, Engine |
15 | 13 | from piccolo.engine.exceptions import TransactionError |
16 | 14 | from piccolo.query.base import Query |
17 | 15 | from piccolo.querystring import QueryString |
18 | 16 | from piccolo.utils.encoding import dump_json, load_json |
| 17 | +from piccolo.utils.lazy_loader import LazyLoader |
19 | 18 | from piccolo.utils.sync import run_sync |
20 | 19 |
|
21 | | -if t.TYPE_CHECKING: |
| 20 | +aiosqlite = LazyLoader("aiosqlite", globals(), "aiosqlite") |
| 21 | + |
| 22 | + |
| 23 | +if t.TYPE_CHECKING: # pragma: no cover |
| 24 | + from aiosqlite import Connection, Cursor # type: ignore |
| 25 | + |
22 | 26 | from piccolo.table import Table |
23 | 27 |
|
24 | 28 | ############################################################################### |
@@ -414,7 +418,7 @@ async def batch(self, query: Query, batch_size: int = 100) -> AsyncBatch: |
414 | 418 | ########################################################################### |
415 | 419 |
|
416 | 420 | async def get_connection(self) -> Connection: |
417 | | - connection = await connect(**self.connection_kwargs) |
| 421 | + connection = await aiosqlite.connect(**self.connection_kwargs) |
418 | 422 | connection.row_factory = dict_factory # type: ignore |
419 | 423 | await connection.execute("PRAGMA foreign_keys = 1") |
420 | 424 | return connection |
@@ -442,7 +446,7 @@ async def _run_in_new_connection( |
442 | 446 | query_type: str = "generic", |
443 | 447 | table: t.Optional[t.Type[Table]] = None, |
444 | 448 | ): |
445 | | - async with connect(**self.connection_kwargs) as connection: |
| 449 | + async with aiosqlite.connect(**self.connection_kwargs) as connection: |
446 | 450 | await connection.execute("PRAGMA foreign_keys = 1") |
447 | 451 |
|
448 | 452 | connection.row_factory = dict_factory # type: ignore |
|
0 commit comments