Skip to main content

Add your description here

Project description

SQLAlchemy Repository

This repository provides a set of base classes for building SQLAlchemy-based repositories. It includes functionality for performing CRUD operations, querying, and updating database records.

Installation

To use this repository, you need to have SQLAlchemy installed in your environment. You can install it using pip:

pip install sqlalchemy-repository

Usage

To use the repository, you need to create a subclass of BaseWriteRepository, BaseReadRepository or BaseRepository for each table you want to manage in your database. Here's an example:

from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import sessionmaker, declarative_base, Mapped, mapped_column
from sqlalchemy_repository import BaseRepository

Base = declarative_base()

class MyTable(Base):
    id: Mapped[int] = mapped_column(primary_key=True)
    title: Mapped[str]

class MyTableRepository(BaseRepository[MyTable, int]):
    model = MyTable

    # Add any additional custom methods here

To use the repository, you need to provide an instance of AsyncSession when creating an instance of the repository class. You can use the sessionmaker class from SQLAlchemy to create the session: from sqlalchemy_repository.repository import BaseWriteRepository, BaseReadRepository

session = sessionmaker(expire_on_commit=False, autocommit=False, autoflush=False, bind=engine)
repo = MyTableRepository(session())

Features

  • full CRUD,
  • Django-like queryset in every repository class
  • support Django-like Q, F filtering
  • annotation and aggregation
  • prefetch_related and select_related

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy_repository-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_repository-1.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_repository-1.0.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_repository-1.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sqlalchemy_repository-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2deb5ab1ec26c16a8c9af52a777cd4a62dba59848eba5429a83ccf42b26a3875
MD5 819b9fb2c29aa28c9a3897b71f2b78a7
BLAKE2b-256 a7d65adbc74558a19022938974d132ba2f6bcc7a4e68173c674aa6c62254bd36

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_repository-1.0.0.tar.gz:

Publisher: release.yml on AstralMortem/sqlalchemy-repository

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlalchemy_repository-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_repository-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2352e449f82b1ab50bd28a170c08fbabff6d5f1830ccdc4f2872d587e91d325f
MD5 09ef934e627a03d5478388357a874476
BLAKE2b-256 37b4c164ad65179cb6aca8384c8166f5492c2583e93525890a5c487a90e10785

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_repository-1.0.0-py3-none-any.whl:

Publisher: release.yml on AstralMortem/sqlalchemy-repository

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page