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. This module implements the usual fix for that well-known broken behaviour, and also adds extra features on top of that.
You can customize, on a per-engine or per-connection basis:
x_sqlite_begin_mode: The type of transaction to be started, such as "BEGIN" or "BEGIN IMMEDIATE" (or "BEGIN CONCURRENT" someday maybe).x_sqlite_foreign_keys: The foreign-key enforcement setting. Can beTrue,False, or"defer".x_sqlite_journal_mode: The journal mode such as"DELETE"or"WAL".
Here's a minimal example:
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},
)
# Configure the engine to use a plain "BEGIN" to start transactions and
# and to use deferred enforcement of foreign keys (recommended!)
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")
# Construct a sessionmaker for each engine.
Session = sessionmaker(engine)
SessionW = sessionmaker(engine_w)
# read-only transaction
with Session() as session:
session.execute(select(...))
# lock the database eagerly for writing
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.1.0.tar.gz.
File metadata
- Download URL: sqlalchemy_boltons-1.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ea9c782c2cd5d9975df8f48fb0ee18b5e802692e3acd80a6a7f536478abe2df
|
|
| MD5 |
d1a8997f0b7c70b61bb0413ea2ae405b
|
|
| BLAKE2b-256 |
b0ec2d472a6f19c72d03cbe622a506de36588ce41731663ada677588a1235a2a
|
File details
Details for the file sqlalchemy_boltons-1.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_boltons-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 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 |
a24dc9a5850c9549237dce5ddee797b62d5916eac2719a3e80644f415d726a32
|
|
| MD5 |
a399d6dcd895b1eea4177c9d37b81afb
|
|
| BLAKE2b-256 |
23b9376012efc4cd070f02cd7c5b52501c592922484d56266e77b88511e256d0
|