Skip to content

tkaymak/format-sql

This branch is up to date with paetzke/format-sql:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0c93acb · Oct 11, 2015
Oct 11, 2015
Oct 11, 2015
Sep 13, 2015
Oct 11, 2015
Oct 11, 2015
Mar 17, 2014
Oct 10, 2015
Mar 17, 2014
Sep 7, 2015
Sep 13, 2015
Mar 17, 2014
Oct 11, 2015

Repository files navigation

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.

About

Makes your SQL readable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%