sqla-utils


Namesqla-utils JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/srittau/sqla-utils
SummaryOpinionated utilities for working with SQLAlchemy
upload_time2023-10-02 12:51:20
maintainer
docs_urlNone
authorSebastian Rittau
requires_python>=3.8,<4
licenseMIT
keywords sqlalchemy orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sqla-utils

Opinionated utilities for working with SQLAlchemy

[![MIT License](https://img.shields.io/pypi/l/sqla-utils.svg)](https://pypi.python.org/pypi/sqla-utils/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqla-utils)](https://pypi.python.org/pypi/sqla-utils/)
[![GitHub](https://img.shields.io/github/release/srittau/sqla-utils/all.svg)](https://github.com/srittau/sqla-utils/releases/)
[![pypi](https://img.shields.io/pypi/v/sqla-utils.svg)](https://pypi.python.org/pypi/sqla-utils/)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/srittau/sqla-utils/test-and-lint.yml?branch=main)](https://github.com/srittau/sqla-utils/actions/workflows/test-and-lint.yml)

## Contents

### Transaction Wrapper

**FIXME**

### `DBObjectBase`

`DBObjectBase` is a base class for mapped classes.

Example:

```python
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:

```python
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:

```python
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**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/srittau/sqla-utils",
    "name": "sqla-utils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4",
    "maintainer_email": "",
    "keywords": "sqlalchemy,orm",
    "author": "Sebastian Rittau",
    "author_email": "srittau@rittau.biz",
    "download_url": "https://files.pythonhosted.org/packages/f6/1b/1e52ac952467cd2aa99a580d95cdebe3635e608ad60487d87b14d31bac75/sqla_utils-0.6.0.tar.gz",
    "platform": null,
    "description": "# sqla-utils\n\nOpinionated utilities for working with SQLAlchemy\n\n[![MIT License](https://img.shields.io/pypi/l/sqla-utils.svg)](https://pypi.python.org/pypi/sqla-utils/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqla-utils)](https://pypi.python.org/pypi/sqla-utils/)\n[![GitHub](https://img.shields.io/github/release/srittau/sqla-utils/all.svg)](https://github.com/srittau/sqla-utils/releases/)\n[![pypi](https://img.shields.io/pypi/v/sqla-utils.svg)](https://pypi.python.org/pypi/sqla-utils/)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/srittau/sqla-utils/test-and-lint.yml?branch=main)](https://github.com/srittau/sqla-utils/actions/workflows/test-and-lint.yml)\n\n## Contents\n\n### Transaction Wrapper\n\n**FIXME**\n\n### `DBObjectBase`\n\n`DBObjectBase` is a base class for mapped classes.\n\nExample:\n\n```python\nfrom datetime import datetime\nfrom sqlalchemy import Column, DateTime, Integer, String\nfrom sqla_utils import DBObjectBase, Transaction\n\nclass DBAppointment(DBObjectBase):\n    __tablename__ = \"appointments\"\n\n    id = Column(Integer, primary_key=True)\n    date = Column(DateTime, nullable=False)\n    description = Column(String(1000), nullable=False, default=\"\")\n```\n\nAppointment items can then be queried like this:\n\n```python\nfrom sqla_utils import begin_transaction\n\nwith begin_transaction() as t:\n    app123 = DBAppointment.fetch_by_id(t, 123)\n    great_apps = DBAppointment.fetch_all(t, DBAppointment.description.like(\"%great%\"))\n```\n\nIt is recommended to add custom query, creation, and update methods:\n\n```python\nclass DBAppointment(DBObjectBase):\n    ...\n\n    @classmethod\n    def create(cls, t: Transaction, date: datetime, description: str) -> DBAppointment:\n        o = cls()\n        o.date = date\n        o.description = description\n        t.add(o)\n        return o\n\n    @classmethod\n    def fetch_all_after(cls, t: Transaction, date: datetime) -> List[DBAppointment]:\n        return cls.fetch_all(t, cls.start >= dates.start)\n\n    def update_description(self, t: Transaction, new_description: str) -> None:\n        self.description = new_description\n        t.changed(self)\n```\n\n### Database Builder\n\n**FIXME**\n\n### pytest Utilities\n\nThe `sqla_utils.test` module contains a few utilities for working with pytest and SQLAlchemy.\n\n**FIXME**\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Opinionated utilities for working with SQLAlchemy",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://github.com/srittau/sqla-utils",
        "Repository": "https://github.com/srittau/sqla-utils"
    },
    "split_keywords": [
        "sqlalchemy",
        "orm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0973f26e4992ccd86c67405f8f8150b8857a623c194be3de89400dd20a8f530f",
                "md5": "39515c575bcab0f4478a64fd7f10b0f0",
                "sha256": "4fc4a7db7286b4cbe86eba0c222b2826981d884341a9451b3e11105374cc6bd6"
            },
            "downloads": -1,
            "filename": "sqla_utils-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "39515c575bcab0f4478a64fd7f10b0f0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4",
            "size": 14428,
            "upload_time": "2023-10-02T12:51:19",
            "upload_time_iso_8601": "2023-10-02T12:51:19.117523Z",
            "url": "https://files.pythonhosted.org/packages/09/73/f26e4992ccd86c67405f8f8150b8857a623c194be3de89400dd20a8f530f/sqla_utils-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f61b1e52ac952467cd2aa99a580d95cdebe3635e608ad60487d87b14d31bac75",
                "md5": "eafe107eb5108e8d082181c5324dcb8b",
                "sha256": "192f3a15b187239d55edc601ef08078e5c3ac2afe53c8e2589759cb21650f799"
            },
            "downloads": -1,
            "filename": "sqla_utils-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "eafe107eb5108e8d082181c5324dcb8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4",
            "size": 12357,
            "upload_time": "2023-10-02T12:51:20",
            "upload_time_iso_8601": "2023-10-02T12:51:20.707520Z",
            "url": "https://files.pythonhosted.org/packages/f6/1b/1e52ac952467cd2aa99a580d95cdebe3635e608ad60487d87b14d31bac75/sqla_utils-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-02 12:51:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "srittau",
    "github_project": "sqla-utils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sqla-utils"
}
        
Elapsed time: 0.28154s