archipy-sqlite 5.25.0__tar.gz → 5.26.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.
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: archipy-sqlite
3
- Version: 5.25.0
3
+ Version: 5.26.0
4
4
  Summary: ArchiPy sqlite adapter.
5
5
  Author-email: Hossein Nejati <hosseinnejati14@gmail.com>
6
6
  License-Expression: Apache-2.0
7
7
  Requires-Python: <4,>=3.14
8
8
  Requires-Dist: aiosqlite>=0.22.1
9
- Requires-Dist: archipy==5.25.0
9
+ Requires-Dist: archipy==5.26.0
10
10
  Requires-Dist: sqlalchemy[asyncio]>=2.1.6
11
11
  Description-Content-Type: text/markdown
12
12
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  from typing import Any, override
4
4
 
5
- from sqlalchemy import URL
5
+ from sqlalchemy import URL, Engine, event
6
6
  from sqlalchemy.exc import SQLAlchemyError
7
7
 
8
8
  from archipy.adapters.base.sqlalchemy.session_managers import (
@@ -92,6 +92,18 @@ def _build_connect_args(configs: SQLiteSQLAlchemyConfig, *, sync_driver: bool) -
92
92
  return connect_args
93
93
 
94
94
 
95
+ def _enable_foreign_keys(engine: Engine) -> None:
96
+ """Turn on foreign key enforcement for every connection the engine opens (SQLite has it off by default)."""
97
+
98
+ @event.listens_for(engine, "connect")
99
+ def set_foreign_keys_pragma(dbapi_connection: Any, _connection_record: object) -> None: # noqa: ANN401
100
+ cursor = dbapi_connection.cursor()
101
+ try:
102
+ cursor.execute("PRAGMA foreign_keys=ON")
103
+ finally:
104
+ cursor.close()
105
+
106
+
95
107
  class SQLiteSQLAlchemySessionManager(BaseSQLAlchemySessionManager[SQLiteSQLAlchemyConfig], metaclass=Singleton):
96
108
  """Synchronous SQLAlchemy session manager for SQLite.
97
109
 
@@ -117,6 +129,8 @@ class SQLiteSQLAlchemySessionManager(BaseSQLAlchemySessionManager[SQLiteSQLAlche
117
129
  configs = orm_config or self._default_config()
118
130
  self._configs = configs # read by _get_connect_args, which the base initializer calls
119
131
  super().__init__(configs)
132
+ if configs.FOREIGN_KEYS:
133
+ _enable_foreign_keys(self.engine)
120
134
 
121
135
  @override
122
136
  def _expected_config_type(self) -> type[SQLiteSQLAlchemyConfig]:
@@ -210,6 +224,8 @@ class AsyncSQLiteSQLAlchemySessionManager(
210
224
  configs = orm_config or self._default_config()
211
225
  self._configs = configs # read by _get_connect_args, which the base initializer calls
212
226
  super().__init__(configs)
227
+ if configs.FOREIGN_KEYS:
228
+ _enable_foreign_keys(self.engine.sync_engine)
213
229
 
214
230
  @override
215
231
  def _expected_config_type(self) -> type[SQLiteSQLAlchemyConfig]:
@@ -5,10 +5,10 @@ authors = [
5
5
  { name = "Hossein Nejati", email = "hosseinnejati14@gmail.com" },
6
6
  ]
7
7
  readme = "README.md"
8
- version = "5.25.0" # This version is set on publish flow!
8
+ version = "5.26.0" # This version is set on publish flow!
9
9
  requires-python = ">=3.14,<4"
10
10
  dependencies = [
11
- "archipy==5.25.0", # Pinned to core version on publish flow!
11
+ "archipy==5.26.0", # Pinned to core version on publish flow!
12
12
  "sqlalchemy[asyncio]>=2.1.6",
13
13
  "aiosqlite>=0.22.1",
14
14
  ]