Skip to main content

qx-db

Database layer for the Qx framework — SQLAlchemy 2 async, a generic Repository[TEntity], UnitOfWork with domain-event routing, transactional outbox, and cursor/offset pagination.

What lives here

  • qx.db.Repository[TEntity] — generic async CRUD with optimistic concurrency (version column), soft-delete, tenant filtering, and allow-listed filter/sort fields.
  • qx.db.UnitOfWork — wraps a SQLAlchemy session; commits the aggregate write and the outbox INSERT in one transaction, then drains and dispatches domain events.
  • qx.db.OutboxRecorder / DefaultOutboxRecorder — persists IntegrationEvent payloads to qx_outbox_events for reliable delivery.
  • qx.db.SessionFactory — factory for AsyncSession instances; injected into repositories.
  • qx.db.make_metadata / make_registry — SQLAlchemy MetaData and registry helpers for imperative mapping (no declarative base).
  • qx.db.standard_audit_columns / uuid_column / jsonb_column — column helpers for consistent schema conventions.
  • qx.db.build_cursor_page / encode_cursor / decode_cursor — opaque cursor pagination utilities.
  • qx.db.include_outbox_table — attaches the qx_outbox_events table to your MetaData.

Defining a repository

from qx.db import Repository
from sqlalchemy import Table

class UserRepository(Repository[User]):
    entity_cls = User
    table: Table  # set to your SQLAlchemy Table at class or instance level
    filterable_fields = {"email", "name", "is_active"}
    sortable_fields = {"created_at", "email"}
    tenanted = False  # set True for multi-tenant tables

Unit of Work

from qx.db import UnitOfWork

class CreateUserHandler:
    def __init__(self, uow: UnitOfWork) -> None:
        self._uow = uow

    async def handle(self, cmd: CreateUserCommand) -> Result[UserDto]:
        async with self._uow.begin() as ctx:
            user_result = User.register(cmd.email, cmd.name)
            user = unwrap(user_result)
            await ctx.users.add(user)
        # commit + outbox INSERT + event dispatch all happened above
        return Result.success(UserDto.from_domain(user))

Design rules

  • Optimistic concurrency — save() uses WHERE id = ? AND version = ?; returns ConflictError (not an exception) on mismatch.
  • Soft-delete by default — list() and get() exclude rows where deleted_at IS NOT NULL unless include_deleted=True.
  • Allow-listed filters — filterable_fields and sortable_fields are class-level sets; querying an unlisted field raises ValueError to prevent controller logic leaking into SQL.
  • Imperative mapping — domain entities are plain dataclasses with no SQLAlchemy decorators. The mapping lives in the infrastructure layer, not the domain.
  • UUID v7 — uuid_column() defaults to UUID v7 primary keys for sequential B-tree index locality.

Metadata

Release files for qx-db 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qx-db 1.1.0
File Size Uploaded Provenance Actions
qx_db-1.1.0.tar.gz 23.8 kB Without provenance Details for qx_db-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qx-db 1.1.0
File Interpreter ABI Platform Actions
qx_db-1.1.0-py3-none-any.whl Python 3 none any Details for qx_db-1.1.0-py3-none-any.whl

Total release size: 49.9 kB

Release files / qx_db-1.1.0.tar.gz

Download URL qx_db-1.1.0.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
577e47a87872a1758469a99f5e2a67731a6a9a1e1dd59c83f83afc056bde8ad5
BLAKE2b-256 checksum
How to use checksums
d4769630c643c0adc940eb80b732e3f9c267458008d95ab81960673832245234
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / qx_db-1.1.0-py3-none-any.whl

Download URL qx_db-1.1.0-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f00d64a987d4d200b4a829b468a935391d8b7cfc274d29243ec2bc16fe8db69
BLAKE2b-256 checksum
How to use checksums
7b1913cee3cc7fc04825c7a05d034dc33f45674fb29647a6660d28e89b6561f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for qx-db 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page