sqla-utils
Opinionated utilities for working with SQLAlchemy
Contents
Transaction Wrapper
FIXME
DBObjectBase
DBObjectBase is a base class for mapped classes.
Example:
from datetime import datetime
from sqlalchemy import Column, DateTime, Integer, String
from sqla_utils import DBObjectBase, Transaction
class DBAppointment(DBObjectBase):
__tablename__ = "appointments"
id = Column(Integer, primary_key=True)
date = Column(DateTime, nullable=False)
description = Column(String(1000), nullable=False, default="")
Appointment items can then be queried like this:
from sqla_utils import begin_transaction
with begin_transaction() as t:
app123 = DBAppointment.fetch_by_id(t, 123)
great_apps = DBAppointment.fetch_all(t, DBAppointment.description.like("%great%"))
It is recommended to add custom query, creation, and update methods:
class DBAppointment(DBObjectBase):
...
@classmethod
def create(cls, t: Transaction, date: datetime, description: str) -> DBAppointment:
o = cls()
o.date = date
o.description = description
t.add(o)
return o
@classmethod
def fetch_all_after(cls, t: Transaction, date: datetime) -> List[DBAppointment]:
return cls.fetch_all(t, cls.start >= dates.start)
def update_description(self, t: Transaction, new_description: str) -> None:
self.description = new_description
t.changed(self)
Database Builder
FIXME
pytest Utilities
The sqla_utils.test module contains a few utilities for working with pytest and SQLAlchemy.
FIXME
Release files for sqla-utils 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqla_utils-0.8.1.tar.gz | 12.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqla_utils-0.8.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.1 kB
Release files / sqla_utils-0.8.1.tar.gz
| Download URL | sqla_utils-0.8.1.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94260ff5bd7b295751fbef1189a3427f4e710396c282f5719c607d1171cfa642
|
|
BLAKE2b-256 checksum How to use checksums |
6375025c8621dafad4b1007e8c6c47d014e4c4c1c6399e72cfc2c5f5a927a61a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / sqla_utils-0.8.1-py3-none-any.whl
| Download URL | sqla_utils-0.8.1-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a58e5173363d3f4e0792fecde9feebe36abaece6840f2c98dfb417deacd2fd17
|
|
BLAKE2b-256 checksum How to use checksums |
43688283f4a8111af8896016538029b3dd05f86b124a5f885e7265d4f6e47e66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|