dnouri / qck

Qck πŸ¦†πŸ‘©β€πŸ’» (pronounced "quack") is a CLI script to conveniently run DuckDB SQL scripts with support for Jina templating

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Qck πŸ¦†πŸ‘©β€πŸ’»

Qck (pronounced "quack") is a CLI script to conveniently run DuckDB SQL scripts with support for Jina 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:

qck myquery.sql

The default is to LIMIT the output to 100 lines. You can override this with the --limit option:

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:

qck myquery.sql --to-parquet myresult.parquet

You can also call qck from within 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.

πŸ–‹οΈ 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:

{% 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 %}

About

Qck πŸ¦†πŸ‘©β€πŸ’» (pronounced "quack") is a CLI script to conveniently run DuckDB SQL scripts with support for Jina templating

License:MIT License


Languages

Language:Python 100.0%