Format, minify, and lint SQL queries from the command line. Formats SQL with proper indentation and keyword casing, minifies by removing whitespace and comments, and lints for common anti-patterns (SELECT *, inconsistent casing, missing semicolons, trailing whitespace). No external dependencies — pure Python. Use when formatting SQL queries, cleaning up SQL files, minifying SQL for production, or checking SQL quality.
零依赖地格式化、压缩和检查SQL代码。
所有命令均使用 scripts/sql_format.py。
bash
python3 scripts/sql_format.py format --sql SELECT id, name FROM users WHERE active = true
python3 scripts/sql_format.py format --input query.sql
python3 scripts/sql_format.py format --input query.sql --output formatted.sql
python3 scripts/sql_format.py format --input query.sql --indent 4 --lowercase
echo SELECT * FROM t | python3 scripts/sql_format.py format --input -
默认在主要子句(SELECT、FROM、WHERE、JOIN、ORDER BY等)前添加换行,缩进AND/OR/ON,并将关键字转换为大写。
bash
python3 scripts/sql_format.py minify --sql SELECT id, name FROM users -- comment
python3 scripts/sql_format.py minify --input query.sql
去除注释,压缩空白,移除括号和逗号周围不必要的空格。
bash
python3 scripts/sql_format.py lint --input query.sql
python3 scripts/sql_format.py lint --sql SELECT * FROM users WHERE 1=1 --json
检查以下内容:SELECT *、多余空格、制表符、!= 与 <>、双逗号、WHERE 1=1、长行(超过120字符)、尾部空白、缺少分号、关键字大小写不一致。
支持SELECT、INSERT、UPDATE、DELETE、CREATE、ALTER、DROP、WITH(CTE)、JOIN(所有类型)、子查询、字符串字面量、双引号标识符、单行和多行注释。
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 sql-formatter-1776104400 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 sql-formatter-1776104400 技能
skillhub install sql-formatter-1776104400
文件大小: 5.67 KB | 发布时间: 2026-4-17 16:13