altqq


Namealtqq JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://altqq.baluyotraf.com
SummaryAlternative Queries: Typed and Reusable Handcrafted SQL
upload_time2024-03-25 15:49:11
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/9c/7d/947f0d84d94bb415e1869dbd00056568367dd383ba9567089f2ddec9bf5c/altqq-0.0.5.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.5",
    "project_urls": {
        "Homepage": "https://altqq.baluyotraf.com",
        "Repository": "https://github.com/baluyotraf/altqq"
    },
    "split_keywords": [
        "database",
        " sql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f66c7269961dc8ce88e218f468682f6bbd47f72d8be3dc7fc3778a5791985bbe",
                "md5": "1648038a0a7b047e7245a0cca8c7049b",
                "sha256": "e1a026817cd102c7ebac671ad595aed5cae94ead92f0bf5f1c23e6a60d1ec93f"
            },
            "downloads": -1,
            "filename": "altqq-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1648038a0a7b047e7245a0cca8c7049b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 9613,
            "upload_time": "2024-03-25T15:49:09",
            "upload_time_iso_8601": "2024-03-25T15:49:09.553152Z",
            "url": "https://files.pythonhosted.org/packages/f6/6c/7269961dc8ce88e218f468682f6bbd47f72d8be3dc7fc3778a5791985bbe/altqq-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c7d947f0d84d94bb415e1869dbd00056568367dd383ba9567089f2ddec9bf5c",
                "md5": "c4025fe54b9f430900a1cf03c61c3541",
                "sha256": "5e6c4af68df7c1c379826f19efa1b133303b3a0ea2e4b8d088c45d1fa8ac9dba"
            },
            "downloads": -1,
            "filename": "altqq-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "c4025fe54b9f430900a1cf03c61c3541",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 7272,
            "upload_time": "2024-03-25T15:49:11",
            "upload_time_iso_8601": "2024-03-25T15:49:11.406859Z",
            "url": "https://files.pythonhosted.org/packages/9c/7d/947f0d84d94bb415e1869dbd00056568367dd383ba9567089f2ddec9bf5c/altqq-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-25 15:49:11",
    "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.21017s