使您的sql可读。

format-sql的Python项目详细描述


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

使您的sql可读。

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

例如:

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java AnimatedVectorDrawable支持库和“pathData”动画   java Qt Jambi:QistTractListModel未显示在QListView中   单击按钮时清除共享首选项   java线程池大小应该远大于内核数+1   linux编译错误java hadoop程序   java不包括findBugs发现的bug   SpringJava。lang.NoClassDefFoundError:org。阿帕奇。贾斯珀。埃尔。ELContextImpl(初始化失败)   使用AVL树的java字典数组   java如何使用数组数据执行jsoup请求?Jsoup使用数组数据发布请求并从php服务器获取json   java jdbc在sql server 2008 r2上存储的png图像提供了不完整的数据   java坏路径警告,它来自哪里?   java从HashMap<String,ArrayList<String>>   java HttpSolrserver已被弃用,无法让HttpSolrClient毫无例外地工作   java如何使用坐标很少的仿射变换?   java在JaxRs中存储会话对象