Skip to main content

Output SQL queries results to file

Project description

Query-Runner

CLI tool to help with running queries.

Quickstart

Pass through a sqlalchemy DB URL and a query to run a query and export to file. (You may need the relevant DB drivers installed also.)

python -m queryrunner show "sqlite:///" "SELECT 'Val' as col1"
python -m queryrunner to-csv "sqlite:///" "SELECT 'Val' as col1" "output.csv"

You can also use an environment variable to contain your connection string, and a file to contain your SQL query.

DB_URI="sqlite:///"
# example-query.sql
SELECT 'Val' as col1
python -m queryrunner to-csv "DB_URI" "example-query.sql" "output.csv"

Query Parameters

You can pass query parameters as extra CLI options, but this only works for strings.

So this will work:

python -m queryrunner show "sqlite:///" "SELECT '5' as col1 WHERE col1=:val" --val 5
python -m queryrunner show "sqlite:///" "SELECT 5 as col1 WHERE CAST(col1 as text)=:val" --val 5

But this will not:

python -m queryrunner show "sqlite:///" "SELECT 5 as col1 WHERE col1=:val" --val 5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queryrunner-0.1.0.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

queryrunner-0.1.0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page