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 details)
Built Distribution
File details
Details for the file queryrunner-0.1.0.tar.gz
.
File metadata
- Download URL: queryrunner-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbd7343f087a2781ed82015694d8d7c149ccfcfee10074a673a1190c2d18b14b |
|
MD5 | 5c03c8f8c73415029465c54632b61678 |
|
BLAKE2b-256 | 075f569f9e01f0b1dcb710ef1ced4a3b194b9c7d8febbd7b09d5183ccb847623 |
File details
Details for the file queryrunner-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: queryrunner-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f602c494a11ed4331d47bbdb625b4ef715f7e73c23af1350e51e6a9becb61d7f |
|
MD5 | a7ba9b0a2efd4e4ec6a9d10fd439d7e7 |
|
BLAKE2b-256 | 74f7ca579dcca85dabb8a14d3595e9e4660ea07fedf1181bd50efffdf702dc5a |