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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for queryrunner-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f602c494a11ed4331d47bbdb625b4ef715f7e73c23af1350e51e6a9becb61d7f |
|
MD5 | a7ba9b0a2efd4e4ec6a9d10fd439d7e7 |
|
BLAKE2b-256 | 74f7ca579dcca85dabb8a14d3595e9e4660ea07fedf1181bd50efffdf702dc5a |