archipy-sqlite 5.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- archipy_sqlite-5.11.0/.gitignore +245 -0
- archipy_sqlite-5.11.0/PKG-INFO +18 -0
- archipy_sqlite-5.11.0/README.md +7 -0
- archipy_sqlite-5.11.0/archipy/adapters/sqlite/__init__.py +1 -0
- archipy_sqlite-5.11.0/archipy/adapters/sqlite/sqlalchemy/__init__.py +1 -0
- archipy_sqlite-5.11.0/archipy/adapters/sqlite/sqlalchemy/adapters.py +78 -0
- archipy_sqlite-5.11.0/archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py +103 -0
- archipy_sqlite-5.11.0/archipy/adapters/sqlite/sqlalchemy/session_managers.py +199 -0
- archipy_sqlite-5.11.0/pyproject.toml +24 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
### JetBrains template
|
|
2
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
3
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
4
|
+
.idea
|
|
5
|
+
# User-specific stuff
|
|
6
|
+
.idea/**/workspace.xml
|
|
7
|
+
.idea/**/tasks.xml
|
|
8
|
+
.idea/**/usage.statistics.xml
|
|
9
|
+
.idea/**/dictionaries
|
|
10
|
+
.idea/**/shelf
|
|
11
|
+
dist
|
|
12
|
+
# AWS User-specific
|
|
13
|
+
.idea/**/aws.xml
|
|
14
|
+
|
|
15
|
+
# Generated files
|
|
16
|
+
.idea/**/contentModel.xml
|
|
17
|
+
|
|
18
|
+
# Sensitive or high-churn files
|
|
19
|
+
.idea/**/dataSources/
|
|
20
|
+
.idea/**/dataSources.ids
|
|
21
|
+
.idea/**/dataSources.local.xml
|
|
22
|
+
.idea/**/sqlDataSources.xml
|
|
23
|
+
.idea/**/dynamic.xml
|
|
24
|
+
.idea/**/uiDesigner.xml
|
|
25
|
+
.idea/**/dbnavigator.xml
|
|
26
|
+
|
|
27
|
+
# Gradle
|
|
28
|
+
.idea/**/gradle.xml
|
|
29
|
+
.idea/**/libraries
|
|
30
|
+
|
|
31
|
+
# Gradle and Maven with auto-import
|
|
32
|
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
33
|
+
# since they will be recreated, and may cause churn. Uncomment if using
|
|
34
|
+
# auto-import.
|
|
35
|
+
# .idea/artifacts
|
|
36
|
+
# .idea/compiler.xml
|
|
37
|
+
# .idea/jarRepositories.xml
|
|
38
|
+
# .idea/modules.xml
|
|
39
|
+
# .idea/*.iml
|
|
40
|
+
# .idea/modules
|
|
41
|
+
# *.iml
|
|
42
|
+
# *.ipr
|
|
43
|
+
|
|
44
|
+
# CMake
|
|
45
|
+
cmake-build-*/
|
|
46
|
+
|
|
47
|
+
# Mongo Explorer plugin
|
|
48
|
+
.idea/**/mongoSettings.xml
|
|
49
|
+
|
|
50
|
+
# File-based project format
|
|
51
|
+
*.iws
|
|
52
|
+
|
|
53
|
+
# IntelliJ
|
|
54
|
+
out/
|
|
55
|
+
|
|
56
|
+
# mpeltonen/sbt-idea plugin
|
|
57
|
+
.idea_modules/
|
|
58
|
+
|
|
59
|
+
# JIRA plugin
|
|
60
|
+
atlassian-ide-plugin.xml
|
|
61
|
+
|
|
62
|
+
# Cursive Clojure plugin
|
|
63
|
+
.idea/replstate.xml
|
|
64
|
+
|
|
65
|
+
# SonarLint plugin
|
|
66
|
+
.idea/sonarlint/
|
|
67
|
+
|
|
68
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
69
|
+
com_crashlytics_export_strings.xml
|
|
70
|
+
crashlytics.properties
|
|
71
|
+
crashlytics-build.properties
|
|
72
|
+
fabric.properties
|
|
73
|
+
|
|
74
|
+
# Editor-based Rest Client
|
|
75
|
+
.idea/httpRequests
|
|
76
|
+
|
|
77
|
+
# Android studio 3.1+ serialized cache file
|
|
78
|
+
.idea/caches/build_file_checksums.ser
|
|
79
|
+
|
|
80
|
+
### Python template
|
|
81
|
+
# Byte-compiled / optimized / DLL files
|
|
82
|
+
__pycache__/
|
|
83
|
+
*.py[cod]
|
|
84
|
+
*$py.class
|
|
85
|
+
|
|
86
|
+
# C extensions
|
|
87
|
+
*.so
|
|
88
|
+
|
|
89
|
+
# Distribution / packaging
|
|
90
|
+
.Python
|
|
91
|
+
build/
|
|
92
|
+
develop-eggs/
|
|
93
|
+
dist/
|
|
94
|
+
downloads/
|
|
95
|
+
eggs/
|
|
96
|
+
.eggs/
|
|
97
|
+
lib/
|
|
98
|
+
lib64/
|
|
99
|
+
parts/
|
|
100
|
+
sdist/
|
|
101
|
+
var/
|
|
102
|
+
wheels/
|
|
103
|
+
share/python-wheels/
|
|
104
|
+
*.egg-info/
|
|
105
|
+
.installed.cfg
|
|
106
|
+
*.egg
|
|
107
|
+
MANIFEST
|
|
108
|
+
|
|
109
|
+
# PyInstaller
|
|
110
|
+
# Usually these files are written by a python script from a template
|
|
111
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
112
|
+
*.manifest
|
|
113
|
+
*.spec
|
|
114
|
+
|
|
115
|
+
# Installer logs
|
|
116
|
+
pip-log.txt
|
|
117
|
+
pip-delete-this-directory.txt
|
|
118
|
+
|
|
119
|
+
# Unit test / coverage reports
|
|
120
|
+
htmlcov/
|
|
121
|
+
.tox/
|
|
122
|
+
.nox/
|
|
123
|
+
.coverage
|
|
124
|
+
.coverage.*
|
|
125
|
+
.cache
|
|
126
|
+
nosetests.xml
|
|
127
|
+
coverage.xml
|
|
128
|
+
*.cover
|
|
129
|
+
*.py,cover
|
|
130
|
+
.hypothesis/
|
|
131
|
+
.pytest_cache/
|
|
132
|
+
cover/
|
|
133
|
+
|
|
134
|
+
# Translations
|
|
135
|
+
*.mo
|
|
136
|
+
*.pot
|
|
137
|
+
|
|
138
|
+
# Django stuff:
|
|
139
|
+
*.log
|
|
140
|
+
local_settings.py
|
|
141
|
+
db.sqlite3
|
|
142
|
+
db.sqlite3-journal
|
|
143
|
+
|
|
144
|
+
# Flask stuff:
|
|
145
|
+
instance/
|
|
146
|
+
.webassets-cache
|
|
147
|
+
|
|
148
|
+
# Scrapy stuff:
|
|
149
|
+
.scrapy
|
|
150
|
+
|
|
151
|
+
# Sphinx documentation
|
|
152
|
+
docs/_build/
|
|
153
|
+
|
|
154
|
+
# PyBuilder
|
|
155
|
+
.pybuilder/
|
|
156
|
+
target/
|
|
157
|
+
|
|
158
|
+
# Jupyter Notebook
|
|
159
|
+
.ipynb_checkpoints
|
|
160
|
+
|
|
161
|
+
# IPython
|
|
162
|
+
profile_default/
|
|
163
|
+
ipython_config.py
|
|
164
|
+
|
|
165
|
+
# pyenv
|
|
166
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
167
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
168
|
+
# .python-version
|
|
169
|
+
|
|
170
|
+
# pipenv
|
|
171
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
172
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
173
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
174
|
+
# install all needed dependencies.
|
|
175
|
+
#Pipfile.lock
|
|
176
|
+
|
|
177
|
+
# poetry
|
|
178
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
179
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
180
|
+
# commonly ignored for libraries.
|
|
181
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
182
|
+
#poetry.lock
|
|
183
|
+
|
|
184
|
+
# pdm
|
|
185
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
186
|
+
#pdm.lock
|
|
187
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
188
|
+
# in version control.
|
|
189
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
190
|
+
.pdm.toml
|
|
191
|
+
|
|
192
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
193
|
+
__pypackages__/
|
|
194
|
+
|
|
195
|
+
# Celery stuff
|
|
196
|
+
celerybeat-schedule
|
|
197
|
+
celerybeat.pid
|
|
198
|
+
|
|
199
|
+
# SageMath parsed files
|
|
200
|
+
*.sage.py
|
|
201
|
+
|
|
202
|
+
# Environments
|
|
203
|
+
.env
|
|
204
|
+
.venv
|
|
205
|
+
env/
|
|
206
|
+
venv/
|
|
207
|
+
ENV/
|
|
208
|
+
env.bak/
|
|
209
|
+
venv.bak/
|
|
210
|
+
|
|
211
|
+
# Spyder project settings
|
|
212
|
+
.spyderproject
|
|
213
|
+
.spyproject
|
|
214
|
+
|
|
215
|
+
# Rope project settings
|
|
216
|
+
.ropeproject
|
|
217
|
+
|
|
218
|
+
# mkdocs documentation
|
|
219
|
+
/site
|
|
220
|
+
|
|
221
|
+
# mypy
|
|
222
|
+
.mypy_cache/
|
|
223
|
+
.dmypy.json
|
|
224
|
+
dmypy.json
|
|
225
|
+
|
|
226
|
+
# Pyre type checker
|
|
227
|
+
.pyre/
|
|
228
|
+
|
|
229
|
+
# pytype static type analyzer
|
|
230
|
+
.pytype/
|
|
231
|
+
|
|
232
|
+
# Cython debug symbols
|
|
233
|
+
cython_debug/
|
|
234
|
+
|
|
235
|
+
# PyCharm
|
|
236
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
237
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
238
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
239
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
240
|
+
#.idea/
|
|
241
|
+
|
|
242
|
+
.ruff_cache
|
|
243
|
+
bandit-report.json
|
|
244
|
+
|
|
245
|
+
.gitattributes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: archipy-sqlite
|
|
3
|
+
Version: 5.11.0
|
|
4
|
+
Summary: ArchiPy sqlite adapter.
|
|
5
|
+
Author-email: Hossein Nejati <hosseinnejati14@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: <4,>=3.14
|
|
8
|
+
Requires-Dist: aiosqlite>=0.22.1
|
|
9
|
+
Requires-Dist: archipy==5.11.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# archipy-sqlite
|
|
13
|
+
|
|
14
|
+
sqlite adapter for [ArchiPy](https://syntaxarc.github.io/ArchiPy/). Install via the core extra:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
uv add "archipy[aiosqlite]"
|
|
18
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""SQLite adapter package."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""SQLite SQLAlchemy adapters for ArchiPy."""
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""SQLite SQLAlchemy adapter implementations."""
|
|
2
|
+
|
|
3
|
+
from typing import override
|
|
4
|
+
|
|
5
|
+
from archipy.adapters.base.sqlalchemy.adapters import (
|
|
6
|
+
AsyncBaseSQLAlchemyAdapter,
|
|
7
|
+
BaseSQLAlchemyAdapter,
|
|
8
|
+
)
|
|
9
|
+
from archipy.adapters.sqlite.sqlalchemy.session_managers import (
|
|
10
|
+
AsyncSQLiteSQLAlchemySessionManager,
|
|
11
|
+
SQLiteSQLAlchemySessionManager,
|
|
12
|
+
)
|
|
13
|
+
from archipy.configs.base_config import BaseConfig
|
|
14
|
+
from archipy.configs.config_template import SQLiteSQLAlchemyConfig
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SQLiteSQLAlchemyAdapter(BaseSQLAlchemyAdapter[SQLiteSQLAlchemyConfig]):
|
|
18
|
+
"""Synchronous SQLAlchemy adapter for SQLite.
|
|
19
|
+
|
|
20
|
+
Inherits from BaseSQLAlchemyAdapter to provide SQLite-specific session management
|
|
21
|
+
and database operations, typically used for in-memory testing.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, orm_config: SQLiteSQLAlchemyConfig | None = None) -> None:
|
|
28
|
+
"""Initialize the SQLite adapter with a session manager.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
32
|
+
"""
|
|
33
|
+
configs = BaseConfig.global_config().SQLITE_SQLALCHEMY if orm_config is None else orm_config
|
|
34
|
+
super().__init__(configs)
|
|
35
|
+
|
|
36
|
+
@override
|
|
37
|
+
def _create_session_manager(self, configs: SQLiteSQLAlchemyConfig) -> SQLiteSQLAlchemySessionManager:
|
|
38
|
+
"""Create a SQLite-specific session manager.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
configs: SQLite configuration.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
A SQLite session manager instance.
|
|
45
|
+
"""
|
|
46
|
+
return SQLiteSQLAlchemySessionManager(configs)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class AsyncSQLiteSQLAlchemyAdapter(AsyncBaseSQLAlchemyAdapter[SQLiteSQLAlchemyConfig]):
|
|
50
|
+
"""Asynchronous SQLAlchemy adapter for SQLite.
|
|
51
|
+
|
|
52
|
+
Inherits from AsyncBaseSQLAlchemyAdapter to provide async SQLite-specific session
|
|
53
|
+
management and database operations, typically used for in-memory testing.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(self, orm_config: SQLiteSQLAlchemyConfig | None = None) -> None:
|
|
60
|
+
"""Initialize the async SQLite adapter with a session manager.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
64
|
+
"""
|
|
65
|
+
configs = BaseConfig.global_config().SQLITE_SQLALCHEMY if orm_config is None else orm_config
|
|
66
|
+
super().__init__(configs)
|
|
67
|
+
|
|
68
|
+
@override
|
|
69
|
+
def _create_async_session_manager(self, configs: SQLiteSQLAlchemyConfig) -> AsyncSQLiteSQLAlchemySessionManager:
|
|
70
|
+
"""Create an async SQLite-specific session manager.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
configs: SQLite configuration.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
An async SQLite session manager instance.
|
|
77
|
+
"""
|
|
78
|
+
return AsyncSQLiteSQLAlchemySessionManager(configs)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Registry for SQLite SQLAlchemy session managers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from archipy.adapters.base.sqlalchemy.session_manager_registry import (
|
|
8
|
+
SessionManagerRegistry,
|
|
9
|
+
)
|
|
10
|
+
from archipy.adapters.sqlite.sqlalchemy.session_managers import (
|
|
11
|
+
AsyncSQLiteSQLAlchemySessionManager,
|
|
12
|
+
SQLiteSQLAlchemySessionManager,
|
|
13
|
+
)
|
|
14
|
+
from archipy.helpers.metaclasses.singleton import Singleton
|
|
15
|
+
from archipy.models.errors import DatabaseConnectionError
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from archipy.adapters.base.sqlalchemy.session_manager_ports import (
|
|
19
|
+
AsyncSessionManagerPort,
|
|
20
|
+
SessionManagerPort,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SQLiteSessionManagerRegistry(SessionManagerRegistry, metaclass=Singleton):
|
|
25
|
+
"""Registry for SQLite SQLAlchemy session managers.
|
|
26
|
+
|
|
27
|
+
This registry provides a centralized access point for both synchronous and
|
|
28
|
+
asynchronous SQLite session managers, implementing the Service Locator pattern.
|
|
29
|
+
It lazily initializes the appropriate session manager when first requested.
|
|
30
|
+
|
|
31
|
+
The registry maintains singleton instances of:
|
|
32
|
+
- A synchronous session manager (SQLiteSQLAlchemySessionManager)
|
|
33
|
+
- An asynchronous session manager (AsyncSQLiteSQLAlchemySessionManager)
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def get_sync_manager(cls) -> SessionManagerPort:
|
|
38
|
+
"""Get the synchronous SQLite session manager instance.
|
|
39
|
+
|
|
40
|
+
Lazily initializes a default SQLiteSQLAlchemySessionManager if none has been set.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
SessionManagerPort: The registered synchronous session manager
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
DatabaseConnectionError: If there's an error initializing the session manager
|
|
47
|
+
"""
|
|
48
|
+
if cls._sync_instance is None:
|
|
49
|
+
try:
|
|
50
|
+
cls._sync_instance = SQLiteSQLAlchemySessionManager()
|
|
51
|
+
except Exception as e:
|
|
52
|
+
raise DatabaseConnectionError(
|
|
53
|
+
database="sqlite",
|
|
54
|
+
) from e
|
|
55
|
+
return cls._sync_instance
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def set_sync_manager(cls, manager: SessionManagerPort) -> None:
|
|
59
|
+
"""Register a synchronous session manager.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
manager: The session manager to register
|
|
63
|
+
"""
|
|
64
|
+
cls._sync_instance = manager
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def get_async_manager(cls) -> AsyncSessionManagerPort:
|
|
68
|
+
"""Get the asynchronous SQLite session manager instance.
|
|
69
|
+
|
|
70
|
+
Lazily initializes a default AsyncSQLiteSQLAlchemySessionManager if none has been set.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
AsyncSessionManagerPort: The registered asynchronous session manager
|
|
74
|
+
|
|
75
|
+
Raises:
|
|
76
|
+
DatabaseConnectionError: If there's an error initializing the session manager
|
|
77
|
+
"""
|
|
78
|
+
if cls._async_instance is None:
|
|
79
|
+
try:
|
|
80
|
+
cls._async_instance = AsyncSQLiteSQLAlchemySessionManager()
|
|
81
|
+
except Exception as e:
|
|
82
|
+
raise DatabaseConnectionError(
|
|
83
|
+
database="sqlite",
|
|
84
|
+
) from e
|
|
85
|
+
return cls._async_instance
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def set_async_manager(cls, manager: AsyncSessionManagerPort) -> None:
|
|
89
|
+
"""Register an asynchronous session manager.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
manager: The async session manager to register
|
|
93
|
+
"""
|
|
94
|
+
cls._async_instance = manager
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def reset(cls) -> None:
|
|
98
|
+
"""Reset the registry to its initial state.
|
|
99
|
+
|
|
100
|
+
This method clears both registered managers, useful for testing.
|
|
101
|
+
"""
|
|
102
|
+
cls._sync_instance = None
|
|
103
|
+
cls._async_instance = None
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""SQLite SQLAlchemy session manager implementations."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, override
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import URL
|
|
6
|
+
from sqlalchemy.exc import SQLAlchemyError
|
|
7
|
+
|
|
8
|
+
from archipy.adapters.base.sqlalchemy.session_managers import (
|
|
9
|
+
AsyncBaseSQLAlchemySessionManager,
|
|
10
|
+
BaseSQLAlchemySessionManager,
|
|
11
|
+
)
|
|
12
|
+
from archipy.configs.base_config import BaseConfig
|
|
13
|
+
from archipy.configs.config_template import SQLiteSQLAlchemyConfig
|
|
14
|
+
from archipy.helpers.metaclasses.singleton import Singleton
|
|
15
|
+
from archipy.models.errors import DatabaseConnectionError
|
|
16
|
+
|
|
17
|
+
_SYNC_DRIVER = "sqlite"
|
|
18
|
+
_ASYNC_DRIVER = "sqlite+aiosqlite"
|
|
19
|
+
_SYNC_DRIVERS = frozenset({"sqlite", "sqlite+pysqlite"})
|
|
20
|
+
# Queue-pool-only arguments; SQLite in-memory engines use SingletonThreadPool/StaticPool, which reject them.
|
|
21
|
+
_QUEUE_POOL_ONLY_KWARGS = frozenset({"pool_size", "max_overflow", "pool_timeout", "pool_use_lifo"})
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _is_in_memory(database: str | None) -> bool:
|
|
25
|
+
"""Return whether the SQLite database path refers to an in-memory database.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
database: The configured SQLite database path.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
bool: True for ``:memory:``, an empty path, or a ``mode=memory`` URI.
|
|
32
|
+
"""
|
|
33
|
+
return not database or database == ":memory:" or "mode=memory" in database
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _sqlite_pool_kwargs(configs: SQLiteSQLAlchemyConfig, pool_kwargs: dict[str, Any]) -> dict[str, Any]:
|
|
37
|
+
"""Drop queue-pool arguments that SQLite in-memory pools do not accept.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
configs: SQLite configuration.
|
|
41
|
+
pool_kwargs: Pool arguments built by the base session manager.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
dict[str, Any]: Pool arguments valid for the pool class SQLAlchemy selects.
|
|
45
|
+
"""
|
|
46
|
+
if not _is_in_memory(configs.DATABASE):
|
|
47
|
+
return pool_kwargs
|
|
48
|
+
return {key: value for key, value in pool_kwargs.items() if key not in _QUEUE_POOL_ONLY_KWARGS}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class SQLiteSQLAlchemySessionManager(BaseSQLAlchemySessionManager[SQLiteSQLAlchemyConfig], metaclass=Singleton):
|
|
52
|
+
"""Synchronous SQLAlchemy session manager for SQLite.
|
|
53
|
+
|
|
54
|
+
Inherits from BaseSQLAlchemySessionManager to provide SQLite-specific session
|
|
55
|
+
management, including connection URL creation and engine configuration.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, orm_config: SQLiteSQLAlchemyConfig | None = None) -> None:
|
|
62
|
+
"""Initialize the SQLite session manager.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
66
|
+
"""
|
|
67
|
+
configs = BaseConfig.global_config().SQLITE_SQLALCHEMY if orm_config is None else orm_config
|
|
68
|
+
super().__init__(configs)
|
|
69
|
+
|
|
70
|
+
@override
|
|
71
|
+
def _expected_config_type(self) -> type[SQLiteSQLAlchemyConfig]:
|
|
72
|
+
"""Return the expected configuration type for SQLite.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
The SQLiteSQLAlchemyConfig class.
|
|
76
|
+
"""
|
|
77
|
+
return SQLiteSQLAlchemyConfig
|
|
78
|
+
|
|
79
|
+
@override
|
|
80
|
+
def _get_database_name(self) -> str:
|
|
81
|
+
"""Return the name of the database being used.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
str: The name of the database ('sqlite').
|
|
85
|
+
"""
|
|
86
|
+
return "sqlite"
|
|
87
|
+
|
|
88
|
+
@override
|
|
89
|
+
def _get_pool_kwargs(self, configs: SQLiteSQLAlchemyConfig) -> dict[str, Any]:
|
|
90
|
+
"""Return pool arguments valid for the SQLite pool class.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
configs: SQLite configuration.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
dict[str, Any]: Pool arguments without queue-pool options for in-memory databases.
|
|
97
|
+
"""
|
|
98
|
+
return _sqlite_pool_kwargs(configs, super()._get_pool_kwargs(configs))
|
|
99
|
+
|
|
100
|
+
@override
|
|
101
|
+
def _create_url(self, configs: SQLiteSQLAlchemyConfig) -> URL:
|
|
102
|
+
"""Create a SQLite connection URL.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
configs: SQLite configuration.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
A SQLAlchemy URL object for SQLite. An async driver such as ``sqlite+aiosqlite``
|
|
109
|
+
is swapped for the sync ``sqlite`` driver.
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
DatabaseConnectionError: If there's an error creating the URL.
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
return URL.create(
|
|
116
|
+
drivername=(_SYNC_DRIVER if configs.DRIVER_NAME == _ASYNC_DRIVER else configs.DRIVER_NAME),
|
|
117
|
+
database=configs.DATABASE,
|
|
118
|
+
)
|
|
119
|
+
except SQLAlchemyError as e:
|
|
120
|
+
raise DatabaseConnectionError(
|
|
121
|
+
database=self._get_database_name(),
|
|
122
|
+
) from e
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class AsyncSQLiteSQLAlchemySessionManager(
|
|
126
|
+
AsyncBaseSQLAlchemySessionManager[SQLiteSQLAlchemyConfig],
|
|
127
|
+
metaclass=Singleton,
|
|
128
|
+
):
|
|
129
|
+
"""Asynchronous SQLAlchemy session manager for SQLite.
|
|
130
|
+
|
|
131
|
+
Inherits from AsyncBaseSQLAlchemySessionManager to provide async SQLite-specific
|
|
132
|
+
session management, including connection URL creation and async engine configuration.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
def __init__(self, orm_config: SQLiteSQLAlchemyConfig | None = None) -> None:
|
|
139
|
+
"""Initialize the async SQLite session manager.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
orm_config: SQLite-specific configuration. If None, uses global config.
|
|
143
|
+
"""
|
|
144
|
+
configs = BaseConfig.global_config().SQLITE_SQLALCHEMY if orm_config is None else orm_config
|
|
145
|
+
super().__init__(configs)
|
|
146
|
+
|
|
147
|
+
@override
|
|
148
|
+
def _expected_config_type(self) -> type[SQLiteSQLAlchemyConfig]:
|
|
149
|
+
"""Return the expected configuration type for SQLite.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
The SQLiteSQLAlchemyConfig class.
|
|
153
|
+
"""
|
|
154
|
+
return SQLiteSQLAlchemyConfig
|
|
155
|
+
|
|
156
|
+
@override
|
|
157
|
+
def _get_database_name(self) -> str:
|
|
158
|
+
"""Return the name of the database being used.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
str: The name of the database ('sqlite').
|
|
162
|
+
"""
|
|
163
|
+
return "sqlite"
|
|
164
|
+
|
|
165
|
+
@override
|
|
166
|
+
def _get_pool_kwargs(self, configs: SQLiteSQLAlchemyConfig) -> dict[str, Any]:
|
|
167
|
+
"""Return pool arguments valid for the SQLite pool class.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
configs: SQLite configuration.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
dict[str, Any]: Pool arguments without queue-pool options for in-memory databases.
|
|
174
|
+
"""
|
|
175
|
+
return _sqlite_pool_kwargs(configs, super()._get_pool_kwargs(configs))
|
|
176
|
+
|
|
177
|
+
@override
|
|
178
|
+
def _create_url(self, configs: SQLiteSQLAlchemyConfig) -> URL:
|
|
179
|
+
"""Create an async SQLite connection URL.
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
configs: SQLite configuration.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
A SQLAlchemy URL object for SQLite. A sync driver such as ``sqlite`` is swapped
|
|
186
|
+
for the async ``sqlite+aiosqlite`` driver.
|
|
187
|
+
|
|
188
|
+
Raises:
|
|
189
|
+
DatabaseConnectionError: If there's an error creating the URL.
|
|
190
|
+
"""
|
|
191
|
+
try:
|
|
192
|
+
return URL.create(
|
|
193
|
+
drivername=(_ASYNC_DRIVER if configs.DRIVER_NAME in _SYNC_DRIVERS else configs.DRIVER_NAME),
|
|
194
|
+
database=configs.DATABASE,
|
|
195
|
+
)
|
|
196
|
+
except SQLAlchemyError as e:
|
|
197
|
+
raise DatabaseConnectionError(
|
|
198
|
+
database=self._get_database_name(),
|
|
199
|
+
) from e
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "archipy-sqlite"
|
|
3
|
+
description = "ArchiPy sqlite adapter."
|
|
4
|
+
authors = [
|
|
5
|
+
{ name = "Hossein Nejati", email = "hosseinnejati14@gmail.com" },
|
|
6
|
+
]
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
version = "5.11.0" # This version is set on publish flow!
|
|
9
|
+
requires-python = ">=3.14,<4"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"archipy==5.11.0", # Pinned to core version on publish flow!
|
|
12
|
+
"aiosqlite>=0.22.1",
|
|
13
|
+
]
|
|
14
|
+
license = "Apache-2.0"
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["hatchling"]
|
|
18
|
+
build-backend = "hatchling.build"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["archipy"]
|
|
22
|
+
|
|
23
|
+
[tool.uv.sources]
|
|
24
|
+
archipy = { workspace = true }
|