Code Monkey home page Code Monkey logo

format-sql's Introduction

format-sql

https://travis-ci.org/paetzke/format-sql.svg?branch=master https://coveralls.io/repos/paetzke/format-sql/badge.svg?branch=master https://readthedocs.org/projects/format-sql/badge/?version=latest

Makes your SQL readable.

https://paetzke.me/static/images/format-sql.gif

An example:

    sql = """ SELECT country, product, SUM(profit) FROM
sales   left join x on x.id=sales.k GROUP BY country,
product having f > 7 and fk=9 limit 5;    """

Will result in:

sql = """
    SELECT
        country,
        product,
        SUM(profit)
    FROM
        sales
        LEFT JOIN x ON
            x.id = sales.k
    GROUP BY
        country,
        product
    HAVING
        f > 7
        AND fk = 9
    LIMIT 5; """

Install format-sql via pip:

$ pip install format-sql

You can then just call format-sql with files and directories:

$ format-sql -h
usage: format-sql [-h] [--types TYPES] [-r] [--no-semicolon] [--version]
                  [--debug] [--dry-run]
                  paths [paths ...]

positional arguments:
  paths

optional arguments:
  -h, --help       show this help message and exit
  --types TYPES    Only process these given file types.
  -r, --recursive  Process files found in subdirectories.
  --no-semicolon   Try to detect SQL queries with no trailing semicolon.
  --version        show program's version number and exit
  --debug          Print available debug information.
  --dry-run        Print the altered output and do not change the file.

For example:

$ format-sql my-file.py

Or recursively with directory:

$ format-sql -r my-directory/

You can try format-sql online: http://format-sql.de.

format-sql's People

Contributors

paetzke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.