Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/snth/prql-exec
https://github.com/snth/prql-exec
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/snth/prql-exec
- Owner: snth
- License: apache-2.0
- Created: 2023-09-10T02:53:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-01T21:41:19.000Z (about 1 year ago)
- Last Synced: 2023-10-02T00:14:43.661Z (about 1 year ago)
- Language: Shell
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prql-exec
`prql-exec` is an experimental shell script to make
system tools that accept SQL input easily accessible
as PRQL libraries.## Getting started
### Install prql-exec
```sh
git clone https://github.com/snth/prql-exec.git
cd prql-exec
ln -sf "$(pwd)/prql-exec" ~/.local/bin/prql-exec
export PRQL_LIB_PATH=".:$(pwd)"
```Since without an `import` statement, `prql-exec` will just
output the SQL produced, I usually just alias it to `prql`
with:```sh
alias prql=prql-exec
```## Example usage
The libraries included by default are:
- [duckdb](duckdb/README.md)
- [git (mergestat)](git/README.md)
- [os (osquery)](os/README.md)
- [postgres](postgres/README.md)
- [sqlite](sqlite/README.md)## Adding libraries
Libraries can be added by creating a / directory
with a file in it. This can then be used
in PRQL queries with the `import ` statement.Moreover, if there is a `.env` file in the /
directory, it will be "sourced" and if there is a
`PRQL_EXEC_COMMAND` environment variable defined in that
file, then that command will be executed via `eval`.
The generated SQL will be passed to it via a `"$sql"`
argument. Options that can be overridden by the user
at runtime should be defined in `PRQL_EXEC_OPTIONS`.
Options that should never be overriden can simple
be included in the COMMAND.The general form of the command definition
should be something like:Please note that the quotes around `$sql` and the lack
of quotes around `$PRQL_EXEC_OPTIONS` are important!For executables that expect to receive SQL via STDIN,
this can usually easily be achieved by using a command
definition as follows:```sh
PRQL_EXEC_COMMAND='echo "$sql" | $PRQL_EXEC_OPTIONS'
```## Adding private libraries
This can be used to set up convenient aliases to internal
databases. For example by creating a file `_prod/.env````sh
# _prod/.env
PGHOST=postgres
PGPORT=5432
PGDATABASE=postgres
PGUSER=postgres
PGPASSWORD=postgres
PRQL_COMPILE_OPTIONS="--target=sql.postgres --hide-signature-comment"
PRQL_EXEC_COMMAND=psql
```you can easily connect to a Postres database with a command like:
```sh
prql-exec "import _prod\nfrom information_schema.sql_features"
```In order to prevent you from accidentally commiting any access
credentials stored in such a file to git, all libraries beginning
with a leading `_` are ignored in the .gitignore.