Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dnouri/qck
Qck π¦π©βπ» (pronounced "quack") is a CLI script to conveniently run DuckDB SQL scripts with support for Jina templating
https://github.com/dnouri/qck
Last synced: 10 days ago
JSON representation
Qck π¦π©βπ» (pronounced "quack") is a CLI script to conveniently run DuckDB SQL scripts with support for Jina templating
- Host: GitHub
- URL: https://github.com/dnouri/qck
- Owner: dnouri
- License: mit
- Created: 2024-01-31T14:04:35.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-15T15:46:20.000Z (8 months ago)
- Last Synced: 2024-11-28T20:16:03.603Z (27 days ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Qck π¦π©βπ»
Qck (pronounced "quack") is a CLI script to conveniently run
[DuckDB](https://duckdb.org/) SQL scripts with support for
[Jina](https://jinja.palletsprojects.com/) templating.## π οΈ Installation
Use `pip install qck` to install. This will make available the `qck`
script.## π Usage
Run `qck --help` to view the built-in documentation.
Running `qck` with just a SQL file will execute the query and print
the results to the terminal:```bash
qck myquery.sql
```The default is to `LIMIT` the output to 100 lines. You can override
this with the `--limit` option:```bash
qck myquery.sql --limit 10 # will only print 10 rows
```To execute a query and write the result to a Parquet file, use
`--to-parquet`:```bash
qck myquery.sql --to-parquet myresult.parquet
```You can also call `qck` from within Python:
```python
from qck import qck
rs = qck("myquery.sql")
rs.to_parquet("myresult.parquet")
```For a full list of arguments to `qck`, please refer to the
[source](qck.py).## ποΈ Templating
Qck can interpret SQL files as Jinja templates, enabling the use of
control structures like for loops within SQL files. Additionally, Qck
introduces a special variable, `import`, in templates, enabling access
to arbitrary Python functions. For instance, consider the following
example, where we import the `glob` function and utilize it to list
files to query from:```jinja
{% for fname in import('glob.glob')('data/*xlsx') %}
SELECT
"Value" AS value,
"RΓ©gion" AS region,
FROM
st_read('{{ fname }}')
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
```