ersatz-table-valued-functions


Nameersatz-table-valued-functions JSON
Version 0.2 PyPI version JSON
download
home_pagehttps://github.com/cldellow/ersatz-table-valued-functions
SummaryA bad idea.
upload_time2023-01-21 19:05:19
maintainer
docs_urlNone
authorColin Dellow
requires_python>=3.7
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ersatz-table-valued-functions

[![PyPI](https://img.shields.io/pypi/v/ersatz-table-valued-functions.svg)](https://pypi.org/project/ersatz-table-valued-functions/)
[![Changelog](https://img.shields.io/github/v/release/cldellow/ersatz-table-valued-functions?include_prereleases&label=changelog)](https://github.com/cldellow/ersatz-table-valued-functions/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/cldellow/ersatz-table-valued-functions/blob/main/LICENSE)

A bad idea.

**ersatz** *(adj.)*: made or used as a substitute, typically an inferior one, for something else.

## Installation

Install this library using `pip`:

    pip install ersatz-table-valued-functions

## Usage

This library lets you rewrite queries like:

```sql
SELECT root, square FROM tbl_squares(3)
```

into queries like:

```sql
WITH _ersatz_1 AS (
  SELECT
    JSON_EXTRACT(value, '$[0]') AS "root",
    JSON_EXTRACT(value, '$[1]') AS "square"
  FROM JSON_EACH((SELECT tbl_squares(3)))
)
SELECT root, square FROM _ersatz_1
```

That is: it translates a query that _looks_ like it needs a table-valued function
into one that uses a scalar-valued function that returns a JSON 2D array.


To use it:

```python
from ersatz_table_valued_functions import rewrite

rewrite('SELECT root, square FROM tbl_squares(3)', { 'TBL_SQUARES': ['root', 'square'] })
```


## Development

To contribute to this library, first checkout the code. Then create a new virtual environment:

    cd ersatz-table-valued-functions
    python -m venv venv
    source venv/bin/activate

Now install the dependencies and test dependencies:

    pip install -e '.[test]'

To run the tests:

    pytest

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cldellow/ersatz-table-valued-functions",
    "name": "ersatz-table-valued-functions",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Colin Dellow",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/64/49/5d87e3019503ed984b6b3f055ed9cde4b95478257afbd42cf7c6230b1018/ersatz-table-valued-functions-0.2.tar.gz",
    "platform": null,
    "description": "# ersatz-table-valued-functions\n\n[![PyPI](https://img.shields.io/pypi/v/ersatz-table-valued-functions.svg)](https://pypi.org/project/ersatz-table-valued-functions/)\n[![Changelog](https://img.shields.io/github/v/release/cldellow/ersatz-table-valued-functions?include_prereleases&label=changelog)](https://github.com/cldellow/ersatz-table-valued-functions/releases)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/cldellow/ersatz-table-valued-functions/blob/main/LICENSE)\n\nA bad idea.\n\n**ersatz** *(adj.)*: made or used as a substitute, typically an inferior one, for something else.\n\n## Installation\n\nInstall this library using `pip`:\n\n    pip install ersatz-table-valued-functions\n\n## Usage\n\nThis library lets you rewrite queries like:\n\n```sql\nSELECT root, square FROM tbl_squares(3)\n```\n\ninto queries like:\n\n```sql\nWITH _ersatz_1 AS (\n  SELECT\n    JSON_EXTRACT(value, '$[0]') AS \"root\",\n    JSON_EXTRACT(value, '$[1]') AS \"square\"\n  FROM JSON_EACH((SELECT tbl_squares(3)))\n)\nSELECT root, square FROM _ersatz_1\n```\n\nThat is: it translates a query that _looks_ like it needs a table-valued function\ninto one that uses a scalar-valued function that returns a JSON 2D array.\n\n\nTo use it:\n\n```python\nfrom ersatz_table_valued_functions import rewrite\n\nrewrite('SELECT root, square FROM tbl_squares(3)', { 'TBL_SQUARES': ['root', 'square'] })\n```\n\n\n## Development\n\nTo contribute to this library, first checkout the code. Then create a new virtual environment:\n\n    cd ersatz-table-valued-functions\n    python -m venv venv\n    source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "A bad idea.",
    "version": "0.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a095efd964cc057b3acc804cb8ff55fb4f45c644308856e802e80a138911292",
                "md5": "fd644ab4deeddbbe554d7f7c93e7ba98",
                "sha256": "b58a91ea72007e89d58c282bc2915d2955415279152fffe6f63831bc7ed0000e"
            },
            "downloads": -1,
            "filename": "ersatz_table_valued_functions-0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fd644ab4deeddbbe554d7f7c93e7ba98",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7765,
            "upload_time": "2023-01-21T19:05:17",
            "upload_time_iso_8601": "2023-01-21T19:05:17.813745Z",
            "url": "https://files.pythonhosted.org/packages/5a/09/5efd964cc057b3acc804cb8ff55fb4f45c644308856e802e80a138911292/ersatz_table_valued_functions-0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "64495d87e3019503ed984b6b3f055ed9cde4b95478257afbd42cf7c6230b1018",
                "md5": "0d97f9f83af620295a7bf571380197ef",
                "sha256": "2247eed8c7784aaee28b1f1ccaa2618d9bc17b222493e416389f2e796fdacd17"
            },
            "downloads": -1,
            "filename": "ersatz-table-valued-functions-0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "0d97f9f83af620295a7bf571380197ef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7263,
            "upload_time": "2023-01-21T19:05:19",
            "upload_time_iso_8601": "2023-01-21T19:05:19.461190Z",
            "url": "https://files.pythonhosted.org/packages/64/49/5d87e3019503ed984b6b3f055ed9cde4b95478257afbd42cf7c6230b1018/ersatz-table-valued-functions-0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-21 19:05:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "cldellow",
    "github_project": "ersatz-table-valued-functions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ersatz-table-valued-functions"
}
        
Elapsed time: 0.03307s