altqq


Namealtqq JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://altqq.baluyotraf.com
SummaryAlternative Queries: Typed and Reusable Handcrafted SQL
upload_time2024-08-02 19:26:34
maintainerbaluyotraf
docs_urlNone
authorbaluyotraf
requires_python<4.0,>=3.9
licenseMIT
keywords database sql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
[![qa](https://github.com/baluyotraf/altqq/actions/workflows/qa.yml/badge.svg)](https://github.com/baluyotraf/altqq/actions/workflows/qa.yml)
[![release](https://github.com/baluyotraf/altqq/actions/workflows/release.yml/badge.svg)](https://github.com/baluyotraf/altqq/actions/workflows/release.yml)

# Alternative Queries

Alternative queries is a library created to help with handcrafted SQL queries.
It works by providing a class that represent the queries where its parameter
types are checked by `Pydantic`.

If you want to write reusable and nested handcrafted SQL queries, you can check
more information on the [Alternative Queries Documentation]. If you want to know
how Alternative Queries can help you, check the [Why use Alternative Queries?]
section of the documentation.

[Alternative Queries Documentation]: https://altqq.baluyotraf.com/stable/
[Why use Alternative Queries?]: https://altqq.baluyotraf.com/stable/rationale/

## Installation

The library is available in the Python Package Index.

```bash
pip install altqq
```

## Quick Start

To start, define a class by inheriting the `altqq.Query` class. The class should
have a query following the python formatting standards. The variable names
inside the `__query__` must match the other attributes defined on the class.

```python
import altqq

class SelectUserByFirstName(altqq.Query):
    __query__ = """
        SELECT * FROM "Users"
        WHERE first_name = {first_name}
    """
    first_name: str
```

The class can be used like a `dataclass`. In fact, classes inheriting the
`altqq.Query` class are turned into a `Pydantic` `dataclass`.

```python
query = SelectUserByFirstName(first_name="arietta")
```

The object can be converted into a query suitable for a DBMS library of your
choice. For example, calling the `altqq.to_pyodbc` function will convert the
object to `PyODBCQuery` which provides the query string and the parameters.

```python
pyodbc_query = altqq.to_pyodbc(query)
print(pyodbc_query.query)
#
#        SELECT * FROM "Users"
#        WHERE first_name = ?
#
print(pyodbc_query.parameters)
# ['arietta']
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://altqq.baluyotraf.com",
    "name": "altqq",
    "maintainer": "baluyotraf",
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": "baluyotraf@outlook.com",
    "keywords": "database, SQL",
    "author": "baluyotraf",
    "author_email": "baluyotraf@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/4e/56/cbc4a61747b19bb80a29be0030ddae020083df33c349a4fb64dcd029dff6/altqq-0.0.7.tar.gz",
    "platform": null,
    "description": "[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)\n[![qa](https://github.com/baluyotraf/altqq/actions/workflows/qa.yml/badge.svg)](https://github.com/baluyotraf/altqq/actions/workflows/qa.yml)\n[![release](https://github.com/baluyotraf/altqq/actions/workflows/release.yml/badge.svg)](https://github.com/baluyotraf/altqq/actions/workflows/release.yml)\n\n# Alternative Queries\n\nAlternative queries is a library created to help with handcrafted SQL queries.\nIt works by providing a class that represent the queries where its parameter\ntypes are checked by `Pydantic`.\n\nIf you want to write reusable and nested handcrafted SQL queries, you can check\nmore information on the [Alternative Queries Documentation]. If you want to know\nhow Alternative Queries can help you, check the [Why use Alternative Queries?]\nsection of the documentation.\n\n[Alternative Queries Documentation]: https://altqq.baluyotraf.com/stable/\n[Why use Alternative Queries?]: https://altqq.baluyotraf.com/stable/rationale/\n\n## Installation\n\nThe library is available in the Python Package Index.\n\n```bash\npip install altqq\n```\n\n## Quick Start\n\nTo start, define a class by inheriting the `altqq.Query` class. The class should\nhave a query following the python formatting standards. The variable names\ninside the `__query__` must match the other attributes defined on the class.\n\n```python\nimport altqq\n\nclass SelectUserByFirstName(altqq.Query):\n    __query__ = \"\"\"\n        SELECT * FROM \"Users\"\n        WHERE first_name = {first_name}\n    \"\"\"\n    first_name: str\n```\n\nThe class can be used like a `dataclass`. In fact, classes inheriting the\n`altqq.Query` class are turned into a `Pydantic` `dataclass`.\n\n```python\nquery = SelectUserByFirstName(first_name=\"arietta\")\n```\n\nThe object can be converted into a query suitable for a DBMS library of your\nchoice. For example, calling the `altqq.to_pyodbc` function will convert the\nobject to `PyODBCQuery` which provides the query string and the parameters.\n\n```python\npyodbc_query = altqq.to_pyodbc(query)\nprint(pyodbc_query.query)\n#\n#        SELECT * FROM \"Users\"\n#        WHERE first_name = ?\n#\nprint(pyodbc_query.parameters)\n# ['arietta']\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Alternative Queries: Typed and Reusable Handcrafted SQL",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://altqq.baluyotraf.com",
        "Repository": "https://github.com/baluyotraf/altqq"
    },
    "split_keywords": [
        "database",
        " sql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5cbc02bdaf5e46a881fbad80f65f19496efa81528b88b2ef6520d62f9269b7bb",
                "md5": "d638133909e4daeb92e6b5fd6bbe55f6",
                "sha256": "78abb1d863dcf28e877026cb8cf09fc757cce41c66a98eda5ef1feee2c848509"
            },
            "downloads": -1,
            "filename": "altqq-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d638133909e4daeb92e6b5fd6bbe55f6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 10438,
            "upload_time": "2024-08-02T19:26:33",
            "upload_time_iso_8601": "2024-08-02T19:26:33.019987Z",
            "url": "https://files.pythonhosted.org/packages/5c/bc/02bdaf5e46a881fbad80f65f19496efa81528b88b2ef6520d62f9269b7bb/altqq-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e56cbc4a61747b19bb80a29be0030ddae020083df33c349a4fb64dcd029dff6",
                "md5": "17b25a11c442c90d048d18f4703effd1",
                "sha256": "3ad2ae1c71fbdfcb4229d9e05ea1745e83c5878304dd4cf468d028ba30b2401c"
            },
            "downloads": -1,
            "filename": "altqq-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "17b25a11c442c90d048d18f4703effd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 7817,
            "upload_time": "2024-08-02T19:26:34",
            "upload_time_iso_8601": "2024-08-02T19:26:34.019073Z",
            "url": "https://files.pythonhosted.org/packages/4e/56/cbc4a61747b19bb80a29be0030ddae020083df33c349a4fb64dcd029dff6/altqq-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-02 19:26:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "baluyotraf",
    "github_project": "altqq",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "altqq"
}
        
Elapsed time: 0.50627s