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.1.0.tar.gz (9.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.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_repository-1.1.0.tar.gz
  • Upload date:
  • Size: 9.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.1.0.tar.gz
Algorithm Hash digest
SHA256 78655d2c23480fc7e3a9e4ee51e6e5bb2438ad4191b194df6f22c2967e17e9d2
MD5 16162c7a7d8bc3a863df18b79c1c697d
BLAKE2b-256 6b841f577244e30a037d94f189b80e47a9189739d4761f73ac1b4b7c30fdbc18

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_repository-1.1.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_repository-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43b672ce306127295673478039e4e2b7a46deb2e3092cdf0b411aa6f4d730288
MD5 48f801b526fc55cafde95f8c9e02e7c3
BLAKE2b-256 a2151fd90d8a0fe8526670e72345e93a5d82076ed71ea88b35136351d725af79

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_repository-1.1.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