使您的sql可读。
format-sql的Python项目详细描述
使您的sql可读。
例如:
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; """
将导致:
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; """
通过pip安装format-sql:
$ pip install format-sql
然后,您可以使用文件和目录调用format-sql:
$ 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.
例如:
$ format-sql my-file.py
或递归使用目录:
$ format-sql -r my-directory/
您可以尝试联机格式化SQL:http://format-sql.de。