Skip to main content

Convert SQL to most human readable format

Project description

readsql

Convert SQL to most human readable format

Installation

pip install readsql

Usage

  • Format SQL code provided in command line
    • readsql <SQL_STRING> -s
    • e.g., readsql 'select sushi from tokyo' -s
    • prints out SELECT sushi FROM tokyo
  • Format an SQL file
    • readsql <FILE_PATH>
    • e.g., readsql sql_example.sql
    • given a Python file (ends with .py), it looks for variables query and formats their insides
    • variable to represent SQL code can be change with -py option
    • e.g., readsql sql_in_python_variable_example.py -py sql
    • given a Python file with this code
def get_query():
    limit = 6
    sql = f"SELEct speed from world where animal='dolphin' limit {limit}"
    return sql

converts it to

def get_query():
    limit = 6
    sql = f"SELECT speed FROM world WHERE animal='dolphin' LIMIT {limit}"
    return sql

Development

Having the repo cloned

  • python readsql tests/sql_example.sql converts example SQL code to easier readable format
  • python readsql tests/sql_in_python_example.py converts example SQL code in Python (it looks for variables query)
  • we can change the SQL variable with -py option python readsql tests/sql_in_python_variable_example.py -py sql
  • python readsql "select gold from mine" -s takes the "select gold from mine" string as input and outputs it formatted

Testing

Have pytest installed and run pytest -v (-v stands for verbose)

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

readsql-0.1.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

readsql-0.1.0-py3-none-any.whl (4.3 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