DataGrip|SQL 自动格式化常用配置(完整版)

DataGrip|SQL 自动格式化常用配置(完整版)

版本:DataGrip 2023.2.1

配置方法:Settings > Code Style > SQL > General(或其他语言)

Case 通用

Word Case 单词大小写设置
  • Keywords:关键字大小写设置(例如 SELECTWHEREAS 等)
  • Identifiers:标识符大小写设置(例如表名、列名等)
  • Built-in types:内置类型大小写设置(例如 INTVARCHAR 等)
  • Custom types:用户类型大小写设置
  • Aliases:别名大小写设置
  • Build-in functions:内置方法的大小写设置(例如 COUNTCASE 等)
  • Quoted identifiers:引用的标识符(例如用引号括起来的表名、列名等)
  • Use original case:
Quotation 引号设置
  • Identifier quotation:标识符前后的引号设置
    • Unquote:去除标识符前后的引号(但是当已被引号括起来的标识符中包含空格等字符时,不会去除)
    • Quote:在标识符前后添加引号
  • Quotation character:引号符号设置

Queries 查询语句

***mon:通用
  • Align the first word of clause:是否将所有子句的左侧对齐
  • Place clause elements on :将子句放在关键字之后的什么位置
  • Place ***ma:将每一行的逗号放置在什么位置(行首或行尾)(DataGrip 在将原本至于行首的格式化为行尾时,会出现很多异常,很不稳定
  • Collapse short statement:是否折叠短的表达式
  • Keep section elements under section header:
  • Align section elements:
  • Align line ***ments at right of elements:对齐每一行之后的注释(在格式化之前,每行注释之前必须有大于等于 1 个空格),包括字段后的注释等
INSERT statements and VALUES clause:INSERT 表达式和 VALUES 字句
  • Place INTO on the new line:将 INTO 关键字放到什么位置
  • Place INTO clause elements on :
  • Place VALUES clause elements (rows) on:
  • Place the opening parenthesis:
  • Place columns or values:
  • Place the closing parenthesis:
  • Wrap columns or values:
  • Place ***ma:
  • Spaces within parentheses:
  • Collapse short multi-row values:是否折叠短的多条待插入数据
UPDATE statement:UPDATE 表达式
  • Place elements on:
  • Wrap elements:
  • Place ***ma:
  • Align =:是否将各个字段的 = 对齐
WITH clause:WITH 字句
  • Place elements on:
  • Wrap subqueries:
  • Place ***ma:
  • Align AS:是否将各个中间表的 AS 对齐
SELECT clause:SELECT 字句
  • Place elements on:
  • Wrap elements:
  • Place ***ma:
  • New line after ALL, DISTINCT:
  • Keep elements on the one line if <=:
  • Use AS:是否使用 AS 或省略
  • Align AS:是否对齐所有的 AS
  • Treat asterisk as a regular element:
FROM caluse:FROM 字句
  • Place elements on:第一个表名是跟在 FROM 关键字之后还是另起一行
  • Wrap elements:FROM 字句是否换行
  • Place ***ma:多个表时逗号的位置
  • Wrap the first JOIN:第一个 JOIN 字句是否换行
  • Wrap the next JOIN:除第一个外的其他 JOIN 字句是否换行
  • ident JOIN:在每个 JOIN 字句前是否加额外的空格
  • Place JOIN in join-only queries under
  • Align joinedtables:是否对其每 join 字句中的表名
  • Align table aliases:
  • Wrap ON/USING:是否在 ON 和 USING 之前换行
  • Place ON/USING under:如果 Wrap ON/USING 开启的话,将 ON/USING 语句与什么对齐
WHERE and HAVING clauses:WHERE 和 HAVING 字句
  • Place elements on:第一个 WHERE 条件是跟在 WHERE 关键字之后还是另起一行
  • Wrap elemnts:括号中的条件是否换行?
  • Place top-level AND / OR:如何防止最上一层的 AND 和 OR 关键字
    • begin:每行的开头位置
    • end:每行的结尾位置
GROUP BY and ORDER BY clauses:GROUP BY 和 ORDER BY 字句
  • Place elements on:
  • Wrap elements:
  • Place ***ma:
  • Align ASC / DESC:
Subquery:子查询
  • Place the opening parenthesis:如何放置子查询的左括号

  • Place subquery:如果放置子查询的主体(即 SELECT 关键字)

  • Place the closing parenthesis:如何放置子查询的右括号

    • Under opening:与左括号的列对齐(新起一行)
  • Space after keyword:在子查询前的关键字(例如 FROM、IN、EXISTS) 之后是否添加空格

  • Spaces within parentheses:在子查询的括号之间是否添加空格

DDL 数据定义语言

CREATE TABLE
  • Place the opening parenthesis:如何放置左括号
  • Place elements:
  • Place the closing parenthesis:如何放置右括号
  • Collapse when short:当建表语句很短时是否折叠为一行
ALTER TABLE
  • Wrap altering instructions:
  • INdent altering instructions
  • Align altering instructions
  • Wrap altered items
  • Indent altered items
  • Align altered items
CREATE or ALTER TABLE
  • Align types:是否对齐各个字段的类型
  • Align defaults:是否对齐各个字段的 defaults 部分
  • Align nullabilities:是否对齐各个字段的 NOT NULL 部分
CONSTRAINT
  • Wrap CONSTRAINT:
  • Wrap KEY/CHECK:
  • Wrap REFERENCES:
  • Wrap cascade and deferrability:
CREATE SCHEMA
  • Indent content:
  • Minimum blank lines between declaration
  • Maximum blank lines between declaration
Views
  • Wrap AS:是否对齐各个字段的 AS
  • Wrap the beginning of the query:
  • Indent query
Postfix options
  • Wrap first option:
  • Wrap next option:vpt
  • Indent options:
  • Align options:

Code

Script
  • Wrap ***mand-ending semicolon:
  • ***mands follow by blank lines:
Impreative ***mons
  • Wrap every statement
  • Keep blank lines in code
Declared variables
  • Wrap section
  • Wrap variables
  • Align types
  • Align assignments
  • Align expressions
Routine arguments
  • Place the opening parenthesis
  • Place elements
  • Place the closing parenthesis
  • Wrap elements
  • Place ***ma
  • Spaces within parentheses
  • Align types
Routine statement
  • Wrap AS
  • Wrap opening $$
  • Wrap the content after opening $$
  • Wrap before closing $$
  • Wrap options after closing $$
IF … THEN … ELSE
  • Wrap THEN
  • Wrap ELSE
  • Wrap inner code
  • indent THEN and ELSE
  • indent END IF
  • Collapse when short:当整个 IF ... THEN ... ELSE 语句很短时,是否折叠为一行
Loops
  • Wrap LOOP
  • Indent Loop
  • Indent END LOOP
  • Collapse when short

Expressions

Cortege
  • Add space before (
  • Space within parentheses
  • Place ***ma to begin
  • Space before ***ma
  • Space after ***ma
Binary expression
  • Use spaces around operators
  • Align operands in binary expressions
  • Space within parenthesized sub-expressions
Function or procedure call
  • Space within parentheses
  • Space before ***ma
  • Space after ***ma
CASE clause:CASE 从句
  • Wrap WHEN:是否在第一个 WHEN 关键字之前换行
  • Indent WHEN if wrapped:如果在第一个 WHEN 关键字之前换行,是否在 WHEN 关键字之前缩进
  • Wrap THEN:是否在 THEN 关键词之前换行
  • Align THEN:是否对齐 THEN 关键字
  • Align ELSE under THEN when THEN aligned:如果 THEN 关键字对齐,那么 ELSE 是否与 THEN 对齐(否则与 WHEN 对齐)
  • Align END:如何将 END 对齐
  • Keep new line after THEN, ELSE
  • Collapse short clause:是否压缩较短的 CASE 从句

Tabs and Indents

  • Use tab character:是否使用制表符(\t
  • Tab size:Tab(制表符)对应的半角字符数
  • Indent:缩进的半角字符数
  • Continuation indent
  • Keep indents on empty lines

Wrapping

Keep when reformatting
  • Line breaks
  • ***ment at first column
转载请说明出处内容投诉
CSS教程_站长资源网 » DataGrip|SQL 自动格式化常用配置(完整版)

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买