format-sql is a tool to format SQL in your Python strings!
Project description
format-sql is a tool to format SQL in your Python strings!
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 [TYPES ...]]] [-r] [--no-semicolon]
paths [paths ...]
positional arguments:
paths
optional arguments:
-h, --help show this help message and exit
--types [TYPES [TYPES ...]]
Process given file types. Default value is "py".
-r, --recursive Process files found in subdirectories.
--no-semicolon Try to detect SQL queries with no trailing semicolon.
You can try format-sql online: http://paetzke.me/format-sql.
Changes
0.2
Add handling for unknown token sequences.
Fix detecting special words. Word boundaries have been ignored.
Single comparison in joins are printed on one line.
Support LIKE and LIKE BINARY for comparison.
0.1
Add parameter --no-semicolon to enable taking SQL queries without semicolon into account.
Copyright (c) 2014, Friedrich Paetzke (paetzke@fastmail.fm). All rights reserved.
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
Built Distribution
Hashes for format_sql-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | addb2491a3e6b5a956c110ae86b372d15c8716c6e51f8fcf94960e356166c711 |
|
MD5 | 4e14f599e7bff8d766eaa9c70bc16352 |
|
BLAKE2b-256 | f77de243919f171cf53619766f75a334555321fe41ba3b30988133c1ab65c395 |