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.1.tar.gz (8.7 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.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_repository-1.0.1.tar.gz
  • Upload date:
  • Size: 8.7 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.1.tar.gz
Algorithm Hash digest
SHA256 f4eb2ef4940315716509463a041490f17b837f9171e1607cfa846654e0516920
MD5 8a7724a01b3eb1c4dc0b7009e373d660
BLAKE2b-256 1b6b9f9b88f785201c2e577c2c6fea40300e3734b7cdeb7eb2e06b49b412b1fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlalchemy_repository-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 666e14d67d6c603393c6e1fac12d1cc5e5515bf8a31ffec73ebaa0cfa34dc1bf
MD5 394f335aac213f907c2bfb1afa4a2040
BLAKE2b-256 d2088f777a1eb90c5e13174a65ef5d26e8c926c22513f07996840c0001cb520f

See more details on using hashes here.

Provenance

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