Utilities that should've been inside SQLAlchemy but aren't
Project description
sqlalchemy_boltons
SQLAlchemy is great. However, it doesn't have everything built-in. Some important things are missing, and need to be "bolted on".
(Name inspired from boltons. Not affiliated.)
sqlite
SQLAlchemy doesn't automatically fix pysqlite's broken transaction handling. Instead, it provides a recipe for doing so inside the documentation. This module implements a fix for that broken behaviour.
You can customize, on a per-engine or per-connection basis:
- The type of transaction to be started, such as BEGIN or BEGIN IMMEDIATE (or BEGIN CONCURRENT someday maybe).
- The foreign-key enforcement setting. Can be
True,False, or"defer". - The journal mode such as DELETE or WAL.
from sqlalchemy.orm import sessionmaker
from sqlalchemy_boltons.sqlite import create_engine_sqlite
engine = create_engine_sqlite("file.db", journal_mode="WAL", timeout=0.5, create_engine_args={"echo": True})
# use standard "BEGIN" and use deferred enforcement of foreign keys
engine = engine.execution_options(x_sqlite_begin_mode=None, x_sqlite_foreign_keys="defer")
# make a separate engine for write transactions using "BEGIN IMMEDIATE" for eager locking
engine_w = engine.execution_options(x_sqlite_begin_mode="IMMEDIATE")
Session = sessionmaker(engine)
SessionW = sessionmaker(engine_w)
with Session() as session:
session.execute(select(...))
# this locks the database eagerly
with SessionW() as session:
session.execute(update(...))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_boltons-1.0.0.tar.gz.
File metadata
- Download URL: sqlalchemy_boltons-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48bcd3f25e286273894b8224ddd138d2d55bb17c7330b2c9417ea21c7525836d
|
|
| MD5 |
64d82c2d193e3798244f83fd63eb6b2d
|
|
| BLAKE2b-256 |
0f5a3608a486f2875e624e66d425fae49dda883704bf8827fa4cb412139e63cf
|
File details
Details for the file sqlalchemy_boltons-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_boltons-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24bba26c1610c42cbe275a04d1ac8ed675927100da1b30e2b485fb905c2b3c66
|
|
| MD5 |
bb007075a52842601a5466abf272060e
|
|
| BLAKE2b-256 |
d663cd08fa03cab1704e6df969126abc9f58f41698ffc0265ed9e334e1fbaca5
|