sqlalchemy-boltons 1.0.0__tar.gz → 1.1.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.
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/CHANGELOG.md +12 -0
- sqlalchemy_boltons-1.1.0/PKG-INFO +73 -0
- sqlalchemy_boltons-1.1.0/README.md +59 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/pyproject.toml +1 -1
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons/sqlite.py +13 -0
- sqlalchemy_boltons-1.1.0/src/sqlalchemy_boltons.egg-info/PKG-INFO +73 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/tests/test_sqlite.py +9 -1
- sqlalchemy_boltons-1.0.0/PKG-INFO +0 -57
- sqlalchemy_boltons-1.0.0/README.md +0 -43
- sqlalchemy_boltons-1.0.0/src/sqlalchemy_boltons.egg-info/PKG-INFO +0 -57
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/AUTHORS.md +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/LICENSE +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/MANIFEST.in +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/doc/Makefile +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/doc/conf.py +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/doc/index.rst +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/doc/make.bat +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/setup.cfg +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/setup.py +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons/__init__.py +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons/py.typed +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons.egg-info/SOURCES.txt +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons.egg-info/top_level.txt +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/tests/__init__.py +0 -0
- {sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/tests/conftest.py +0 -0
@@ -4,6 +4,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
+
## [1.1.0] - 2025-03-11
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
- `sqlite`: Use an unlimited-size QueuePool by default.
|
12
|
+
|
13
|
+
## [1.0.1] - 2025-02-22
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Improve the documentation.
|
18
|
+
|
7
19
|
## [1.0.0] - 2025-02-22
|
8
20
|
|
9
21
|
### Added
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: sqlalchemy_boltons
|
3
|
+
Version: 1.1.0
|
4
|
+
Summary: Utilities that should've been inside SQLAlchemy but aren't
|
5
|
+
Author-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
6
|
+
Maintainer-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
7
|
+
License: MIT
|
8
|
+
Project-URL: Homepage, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/
|
9
|
+
Project-URL: Changelog, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/file?name=CHANGELOG.md&ci=trunk
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
License-File: AUTHORS.md
|
14
|
+
|
15
|
+
# sqlalchemy_boltons
|
16
|
+
|
17
|
+
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be
|
18
|
+
"bolted on".
|
19
|
+
|
20
|
+
(Name inspired from [boltons](https://pypi.org/project/boltons/). Not affiliated.)
|
21
|
+
|
22
|
+
## sqlite
|
23
|
+
|
24
|
+
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. This module implements the
|
25
|
+
[usual fix](https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl)
|
26
|
+
for that well-known broken behaviour, and also adds extra features on top of that.
|
27
|
+
|
28
|
+
You can [customize](https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Engine.execution_options),
|
29
|
+
on a per-engine or per-connection basis:
|
30
|
+
|
31
|
+
- `x_sqlite_begin_mode`: The type of transaction to be started, such as "BEGIN" or
|
32
|
+
"[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html)" (or
|
33
|
+
"[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md)" someday maybe).
|
34
|
+
- `x_sqlite_foreign_keys`: The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Can be
|
35
|
+
`True`, `False`, or `"defer"`.
|
36
|
+
- `x_sqlite_journal_mode`: The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as
|
37
|
+
`"DELETE"` or `"WAL"`.
|
38
|
+
|
39
|
+
Here's a minimal example:
|
40
|
+
|
41
|
+
```python
|
42
|
+
from sqlalchemy.orm import sessionmaker
|
43
|
+
from sqlalchemy_boltons.sqlite import create_engine_sqlite
|
44
|
+
|
45
|
+
engine = create_engine_sqlite(
|
46
|
+
"file.db",
|
47
|
+
journal_mode="WAL",
|
48
|
+
timeout=0.5,
|
49
|
+
create_engine_args={"echo": True},
|
50
|
+
)
|
51
|
+
|
52
|
+
# Configure the engine to use a plain "BEGIN" to start transactions and
|
53
|
+
# and to use deferred enforcement of foreign keys (recommended!)
|
54
|
+
engine = engine.execution_options(
|
55
|
+
x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer"
|
56
|
+
)
|
57
|
+
|
58
|
+
# Make a separate engine for write transactions using "BEGIN IMMEDIATE"
|
59
|
+
# for eager locking.
|
60
|
+
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
|
61
|
+
|
62
|
+
# Construct a sessionmaker for each engine.
|
63
|
+
Session = sessionmaker(engine)
|
64
|
+
SessionW = sessionmaker(engine_w)
|
65
|
+
|
66
|
+
# read-only transaction
|
67
|
+
with Session() as session:
|
68
|
+
session.execute(select(...))
|
69
|
+
|
70
|
+
# lock the database eagerly for writing
|
71
|
+
with SessionW() as session:
|
72
|
+
session.execute(update(...))
|
73
|
+
```
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# sqlalchemy_boltons
|
2
|
+
|
3
|
+
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be
|
4
|
+
"bolted on".
|
5
|
+
|
6
|
+
(Name inspired from [boltons](https://pypi.org/project/boltons/). Not affiliated.)
|
7
|
+
|
8
|
+
## sqlite
|
9
|
+
|
10
|
+
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. This module implements the
|
11
|
+
[usual fix](https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl)
|
12
|
+
for that well-known broken behaviour, and also adds extra features on top of that.
|
13
|
+
|
14
|
+
You can [customize](https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Engine.execution_options),
|
15
|
+
on a per-engine or per-connection basis:
|
16
|
+
|
17
|
+
- `x_sqlite_begin_mode`: The type of transaction to be started, such as "BEGIN" or
|
18
|
+
"[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html)" (or
|
19
|
+
"[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md)" someday maybe).
|
20
|
+
- `x_sqlite_foreign_keys`: The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Can be
|
21
|
+
`True`, `False`, or `"defer"`.
|
22
|
+
- `x_sqlite_journal_mode`: The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as
|
23
|
+
`"DELETE"` or `"WAL"`.
|
24
|
+
|
25
|
+
Here's a minimal example:
|
26
|
+
|
27
|
+
```python
|
28
|
+
from sqlalchemy.orm import sessionmaker
|
29
|
+
from sqlalchemy_boltons.sqlite import create_engine_sqlite
|
30
|
+
|
31
|
+
engine = create_engine_sqlite(
|
32
|
+
"file.db",
|
33
|
+
journal_mode="WAL",
|
34
|
+
timeout=0.5,
|
35
|
+
create_engine_args={"echo": True},
|
36
|
+
)
|
37
|
+
|
38
|
+
# Configure the engine to use a plain "BEGIN" to start transactions and
|
39
|
+
# and to use deferred enforcement of foreign keys (recommended!)
|
40
|
+
engine = engine.execution_options(
|
41
|
+
x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer"
|
42
|
+
)
|
43
|
+
|
44
|
+
# Make a separate engine for write transactions using "BEGIN IMMEDIATE"
|
45
|
+
# for eager locking.
|
46
|
+
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
|
47
|
+
|
48
|
+
# Construct a sessionmaker for each engine.
|
49
|
+
Session = sessionmaker(engine)
|
50
|
+
SessionW = sessionmaker(engine_w)
|
51
|
+
|
52
|
+
# read-only transaction
|
53
|
+
with Session() as session:
|
54
|
+
session.execute(select(...))
|
55
|
+
|
56
|
+
# lock the database eagerly for writing
|
57
|
+
with SessionW() as session:
|
58
|
+
session.execute(update(...))
|
59
|
+
```
|
@@ -54,6 +54,16 @@ class SQLAlchemySqliteTransactionFix:
|
|
54
54
|
This class exists because sqlalchemy doesn't automatically fix pysqlite's stupid default behaviour. Additionally,
|
55
55
|
we implement support for foreign keys.
|
56
56
|
|
57
|
+
The execution options we look for are as follows:
|
58
|
+
|
59
|
+
- `x_sqlite_begin_mode`: The type of transaction to be started, such as "BEGIN" or
|
60
|
+
"[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html)" (or
|
61
|
+
"[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md)" someday maybe).
|
62
|
+
- `x_sqlite_foreign_keys`: The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Must be
|
63
|
+
`True`, `False`, or `"defer"`.
|
64
|
+
- `x_sqlite_journal_mode`: The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as
|
65
|
+
`"DELETE"` or `"WAL"`. Optional.
|
66
|
+
|
57
67
|
https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl
|
58
68
|
"""
|
59
69
|
|
@@ -188,6 +198,9 @@ def create_engine_sqlite(
|
|
188
198
|
# always default to QueuePool
|
189
199
|
if (k := "poolclass") not in create_engine_args:
|
190
200
|
create_engine_args[k] = sap.QueuePool
|
201
|
+
if (k := "max_overflow") not in create_engine_args:
|
202
|
+
# for SQLite it doesn't make sense to restrict the number of concurrent (read-only) connections
|
203
|
+
create_engine_args["max_overflow"] = -1
|
191
204
|
|
192
205
|
if (v := create_engine_args.get(k := "connect_args")) is None:
|
193
206
|
create_engine_args[k] = v = {}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: sqlalchemy-boltons
|
3
|
+
Version: 1.1.0
|
4
|
+
Summary: Utilities that should've been inside SQLAlchemy but aren't
|
5
|
+
Author-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
6
|
+
Maintainer-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
7
|
+
License: MIT
|
8
|
+
Project-URL: Homepage, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/
|
9
|
+
Project-URL: Changelog, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/file?name=CHANGELOG.md&ci=trunk
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
License-File: AUTHORS.md
|
14
|
+
|
15
|
+
# sqlalchemy_boltons
|
16
|
+
|
17
|
+
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be
|
18
|
+
"bolted on".
|
19
|
+
|
20
|
+
(Name inspired from [boltons](https://pypi.org/project/boltons/). Not affiliated.)
|
21
|
+
|
22
|
+
## sqlite
|
23
|
+
|
24
|
+
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. This module implements the
|
25
|
+
[usual fix](https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl)
|
26
|
+
for that well-known broken behaviour, and also adds extra features on top of that.
|
27
|
+
|
28
|
+
You can [customize](https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Engine.execution_options),
|
29
|
+
on a per-engine or per-connection basis:
|
30
|
+
|
31
|
+
- `x_sqlite_begin_mode`: The type of transaction to be started, such as "BEGIN" or
|
32
|
+
"[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html)" (or
|
33
|
+
"[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md)" someday maybe).
|
34
|
+
- `x_sqlite_foreign_keys`: The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Can be
|
35
|
+
`True`, `False`, or `"defer"`.
|
36
|
+
- `x_sqlite_journal_mode`: The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as
|
37
|
+
`"DELETE"` or `"WAL"`.
|
38
|
+
|
39
|
+
Here's a minimal example:
|
40
|
+
|
41
|
+
```python
|
42
|
+
from sqlalchemy.orm import sessionmaker
|
43
|
+
from sqlalchemy_boltons.sqlite import create_engine_sqlite
|
44
|
+
|
45
|
+
engine = create_engine_sqlite(
|
46
|
+
"file.db",
|
47
|
+
journal_mode="WAL",
|
48
|
+
timeout=0.5,
|
49
|
+
create_engine_args={"echo": True},
|
50
|
+
)
|
51
|
+
|
52
|
+
# Configure the engine to use a plain "BEGIN" to start transactions and
|
53
|
+
# and to use deferred enforcement of foreign keys (recommended!)
|
54
|
+
engine = engine.execution_options(
|
55
|
+
x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer"
|
56
|
+
)
|
57
|
+
|
58
|
+
# Make a separate engine for write transactions using "BEGIN IMMEDIATE"
|
59
|
+
# for eager locking.
|
60
|
+
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
|
61
|
+
|
62
|
+
# Construct a sessionmaker for each engine.
|
63
|
+
Session = sessionmaker(engine)
|
64
|
+
SessionW = sessionmaker(engine_w)
|
65
|
+
|
66
|
+
# read-only transaction
|
67
|
+
with Session() as session:
|
68
|
+
session.execute(select(...))
|
69
|
+
|
70
|
+
# lock the database eagerly for writing
|
71
|
+
with SessionW() as session:
|
72
|
+
session.execute(update(...))
|
73
|
+
```
|
@@ -54,7 +54,9 @@ def simple_sqlite_engine(tmp_path, database_type):
|
|
54
54
|
else:
|
55
55
|
raise AssertionError
|
56
56
|
|
57
|
-
return _sq.create_engine_sqlite(
|
57
|
+
return _sq.create_engine_sqlite(
|
58
|
+
path, journal_mode="WAL", timeout=0.5, create_engine_args={"echo": True, "pool_timeout": 2}
|
59
|
+
)
|
58
60
|
|
59
61
|
|
60
62
|
@pytest.mark.parametrize("database_type", ["file", "memory"])
|
@@ -117,6 +119,12 @@ def test_transaction(simple_sqlite_engine, database_type):
|
|
117
119
|
assert len(s.execute(sa.select(Example)).all()) == 2
|
118
120
|
s.commit()
|
119
121
|
|
122
|
+
with contextlib.ExitStack() as exit_stack:
|
123
|
+
# concurrent connection count
|
124
|
+
for i in range(30):
|
125
|
+
exit_stack.enter_context(s := SessionR())
|
126
|
+
assert len(s.execute(sa.select(Example)).all()) == 2
|
127
|
+
|
120
128
|
|
121
129
|
@pytest.mark.parametrize("path_type", ["str", "Path"])
|
122
130
|
def test_create_engine_path(tmp_path, path_type):
|
@@ -1,57 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: sqlalchemy_boltons
|
3
|
-
Version: 1.0.0
|
4
|
-
Summary: Utilities that should've been inside SQLAlchemy but aren't
|
5
|
-
Author-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
6
|
-
Maintainer-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
7
|
-
License: MIT
|
8
|
-
Project-URL: Homepage, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/
|
9
|
-
Project-URL: Changelog, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/file?name=CHANGELOG.md&ci=trunk
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
11
|
-
Description-Content-Type: text/markdown
|
12
|
-
License-File: LICENSE
|
13
|
-
License-File: AUTHORS.md
|
14
|
-
|
15
|
-
# sqlalchemy_boltons
|
16
|
-
|
17
|
-
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be
|
18
|
-
"bolted on".
|
19
|
-
|
20
|
-
(Name inspired from [boltons](https://pypi.org/project/boltons/). Not affiliated.)
|
21
|
-
|
22
|
-
## sqlite
|
23
|
-
|
24
|
-
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. Instead, it provides a recipe for doing so
|
25
|
-
inside the [documentation](https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl).
|
26
|
-
This module implements a fix for that broken behaviour.
|
27
|
-
|
28
|
-
You can customize, on a per-engine or per-connection basis:
|
29
|
-
|
30
|
-
- The type of transaction to be started, such as BEGIN or
|
31
|
-
[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html) (or
|
32
|
-
[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md) someday maybe).
|
33
|
-
- The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Can be `True`, `False`, or `"defer"`.
|
34
|
-
- The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as DELETE or WAL.
|
35
|
-
|
36
|
-
```python
|
37
|
-
from sqlalchemy.orm import sessionmaker
|
38
|
-
from sqlalchemy_boltons.sqlite import create_engine_sqlite
|
39
|
-
|
40
|
-
engine = create_engine_sqlite("file.db", journal_mode="WAL", timeout=0.5, create_engine_args={"echo": True})
|
41
|
-
|
42
|
-
# use standard "BEGIN" and use deferred enforcement of foreign keys
|
43
|
-
engine = engine.execution_options(x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer")
|
44
|
-
|
45
|
-
# make a separate engine for write transactions using "BEGIN IMMEDIATE" for eager locking
|
46
|
-
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
|
47
|
-
|
48
|
-
Session = sessionmaker(engine)
|
49
|
-
SessionW = sessionmaker(engine_w)
|
50
|
-
|
51
|
-
with Session() as session:
|
52
|
-
session.execute(select(...))
|
53
|
-
|
54
|
-
# this locks the database eagerly
|
55
|
-
with SessionW() as session:
|
56
|
-
session.execute(update(...))
|
57
|
-
```
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# sqlalchemy_boltons
|
2
|
-
|
3
|
-
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be
|
4
|
-
"bolted on".
|
5
|
-
|
6
|
-
(Name inspired from [boltons](https://pypi.org/project/boltons/). Not affiliated.)
|
7
|
-
|
8
|
-
## sqlite
|
9
|
-
|
10
|
-
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. Instead, it provides a recipe for doing so
|
11
|
-
inside the [documentation](https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl).
|
12
|
-
This module implements a fix for that broken behaviour.
|
13
|
-
|
14
|
-
You can customize, on a per-engine or per-connection basis:
|
15
|
-
|
16
|
-
- The type of transaction to be started, such as BEGIN or
|
17
|
-
[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html) (or
|
18
|
-
[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md) someday maybe).
|
19
|
-
- The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Can be `True`, `False`, or `"defer"`.
|
20
|
-
- The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as DELETE or WAL.
|
21
|
-
|
22
|
-
```python
|
23
|
-
from sqlalchemy.orm import sessionmaker
|
24
|
-
from sqlalchemy_boltons.sqlite import create_engine_sqlite
|
25
|
-
|
26
|
-
engine = create_engine_sqlite("file.db", journal_mode="WAL", timeout=0.5, create_engine_args={"echo": True})
|
27
|
-
|
28
|
-
# use standard "BEGIN" and use deferred enforcement of foreign keys
|
29
|
-
engine = engine.execution_options(x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer")
|
30
|
-
|
31
|
-
# make a separate engine for write transactions using "BEGIN IMMEDIATE" for eager locking
|
32
|
-
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
|
33
|
-
|
34
|
-
Session = sessionmaker(engine)
|
35
|
-
SessionW = sessionmaker(engine_w)
|
36
|
-
|
37
|
-
with Session() as session:
|
38
|
-
session.execute(select(...))
|
39
|
-
|
40
|
-
# this locks the database eagerly
|
41
|
-
with SessionW() as session:
|
42
|
-
session.execute(update(...))
|
43
|
-
```
|
@@ -1,57 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: sqlalchemy-boltons
|
3
|
-
Version: 1.0.0
|
4
|
-
Summary: Utilities that should've been inside SQLAlchemy but aren't
|
5
|
-
Author-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
6
|
-
Maintainer-email: Eduard Christian Dumitrescu <eduard.c.dumitrescu@gmail.com>
|
7
|
-
License: MIT
|
8
|
-
Project-URL: Homepage, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/
|
9
|
-
Project-URL: Changelog, https://hydra.ecd.space/deaduard/sqlalchemy_boltons/file?name=CHANGELOG.md&ci=trunk
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
11
|
-
Description-Content-Type: text/markdown
|
12
|
-
License-File: LICENSE
|
13
|
-
License-File: AUTHORS.md
|
14
|
-
|
15
|
-
# sqlalchemy_boltons
|
16
|
-
|
17
|
-
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be
|
18
|
-
"bolted on".
|
19
|
-
|
20
|
-
(Name inspired from [boltons](https://pypi.org/project/boltons/). Not affiliated.)
|
21
|
-
|
22
|
-
## sqlite
|
23
|
-
|
24
|
-
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. Instead, it provides a recipe for doing so
|
25
|
-
inside the [documentation](https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl).
|
26
|
-
This module implements a fix for that broken behaviour.
|
27
|
-
|
28
|
-
You can customize, on a per-engine or per-connection basis:
|
29
|
-
|
30
|
-
- The type of transaction to be started, such as BEGIN or
|
31
|
-
[BEGIN IMMEDIATE](https://www.sqlite.org/lang_transaction.html) (or
|
32
|
-
[BEGIN CONCURRENT](https://www.sqlite.org/cgi/src/doc/begin-concurrent/doc/begin_concurrent.md) someday maybe).
|
33
|
-
- The [foreign-key enforcement setting](https://www.sqlite.org/foreignkeys.html). Can be `True`, `False`, or `"defer"`.
|
34
|
-
- The [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) such as DELETE or WAL.
|
35
|
-
|
36
|
-
```python
|
37
|
-
from sqlalchemy.orm import sessionmaker
|
38
|
-
from sqlalchemy_boltons.sqlite import create_engine_sqlite
|
39
|
-
|
40
|
-
engine = create_engine_sqlite("file.db", journal_mode="WAL", timeout=0.5, create_engine_args={"echo": True})
|
41
|
-
|
42
|
-
# use standard "BEGIN" and use deferred enforcement of foreign keys
|
43
|
-
engine = engine.execution_options(x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer")
|
44
|
-
|
45
|
-
# make a separate engine for write transactions using "BEGIN IMMEDIATE" for eager locking
|
46
|
-
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
|
47
|
-
|
48
|
-
Session = sessionmaker(engine)
|
49
|
-
SessionW = sessionmaker(engine_w)
|
50
|
-
|
51
|
-
with Session() as session:
|
52
|
-
session.execute(select(...))
|
53
|
-
|
54
|
-
# this locks the database eagerly
|
55
|
-
with SessionW() as session:
|
56
|
-
session.execute(update(...))
|
57
|
-
```
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons.egg-info/SOURCES.txt
RENAMED
File without changes
|
File without changes
|
{sqlalchemy_boltons-1.0.0 → sqlalchemy_boltons-1.1.0}/src/sqlalchemy_boltons.egg-info/top_level.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|