datasette-ersatz-table-valued-functions
ersatz (adj.): made or used as a substitute, typically an inferior one, for something else.
Enable a limited form of table-valued functions.
See also ersatz-table-valued-functions.
Installation
Install this plugin in the same environment as Datasette.
datasette install datasette-ersatz-table-valued-functions
Usage
Write a plugin that registers a table-valued function in the startup hook:
from datasette import hookimpl
from datasette_ersatz_table_valued_functions import create_table_function
def tbl_squares(n):
return [(i, i*i) for i in range(n)]
@hookimpl
def startup():
create_table_function('tbl_squares', 1, tbl_squares, ['root', 'square'])
You can then query this in Datasette:
SELECT root FROM tbl_squares(10) WHERE square % 2 = 0 AND square < 50
will emit 0, 2, 4, 6.
The parameters to the function can come from a subselect, which could target any table and be arbitrarily complex:
SELECT root FROM tbl_squares((SELECT 10))
You can do whatever with the output of this function -- join it, aggregate it, etc.
What you can't do is use a join as the source of input to the function:
WITH xs AS (SELECT 10 AS x) SELECT root FROM tbl_squares(x), xs
Queries that aren't supported are passed as-is to SQLite, which will itself then reject them since no such table function is registered.
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-ersatz-table-valued-functions
python3 -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
Metadata
Release files for datasette-ersatz-table-valued-functions 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datasette-ersatz-table-valued-functions-0.2.tar.gz | 6.9 kB | Without provenance | Details for datasette-ersatz-table-valued-functions-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datasette_ersatz_table_valued_functions-0.2-py3-none-any.whl | Python 3 | none | any | Details for datasette_ersatz_table_valued_functions-0.2-py3-none-any.whl |
Total release size: 14.6 kB
Release files / datasette-ersatz-table-valued-functions-0.2.tar.gz
| Download URL | datasette-ersatz-table-valued-functions-0.2.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc89271db3a7b15d9bee060a48b6a6defa84e4f5e6f6d0aaed20eca46c67ce54
|
|
BLAKE2b-256 checksum How to use checksums |
a7a19a71dade6322cb7910604ee4695848134fb196542b6669a5ecbe61278a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / datasette_ersatz_table_valued_functions-0.2-py3-none-any.whl
| Download URL | datasette_ersatz_table_valued_functions-0.2-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb821827c6cfb546aa8c32fda507d582319f5365d3e7a52c58499aaff4bc1d08
|
|
BLAKE2b-256 checksum How to use checksums |
15f3425aed306db7efbb5532814e751d5ebb2198aa009d788c8c81efc1faa827
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for datasette-ersatz-table-valued-functions 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.