最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

formatting - Is it possible to achieve JetBrains-like type alignment with SQLFluff? - Stack Overflow

programmeradmin3浏览0评论

I’m using SQLFluff for formatting SQL files and trying to replicate the behavior of JetBrains IDEs where types are perfectly aligned under each other, and constraints (e.g., NOT NULL) dynamically adjust with spaces for proper alignment. Here’s an example of the alignment I’m trying to achieve:

CREATE TABLE products (
    product_id   BIGINT      PRIMARY KEY,
    name         TEXT        NOT NULL,
    description  TEXT,
    price        NUMERIC(10, 2) NOT NULL,
    in_stock     BOOLEAN     DEFAULT TRUE,
    created_at   TIMESTAMP   DEFAULT now()
);

The key formatting features I’m looking for are:

  1. Dynamic type alignment: Types (TEXT, BIGINT, NUMERIC) should align under each other.
  2. Constraint alignment: Keywords like NOT NULL, DEFAULT, or PRIMARY KEY should also align dynamically.

I’ve explored the following SQLFluff configuration: • layout.indent: For consistent indentation. • layout.spacing: To prevent extra spaces. • Rules like layout.type:datatype and layout.type:column_constraint for alignment.

Here’s an excerpt from my .sqlfluff file:

[sqlfluff]
dialect = postgres

[sqlfluff:rules:layout.indent]
indent_unit = space
tab_space_size = 4

[sqlfluff:layout:type:datatype]
align_with = type

[sqlfluff:layout:type:column_constraint]
align_with = type

Any help or suggestions would be greatly appreciated!

发布评论

评论列表(0)

  1. 暂无评论