Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Vertical alignment #72

Closed
ufukty opened this issue Jan 25, 2024 · 1 comment
Closed

Feature request: Vertical alignment #72

ufukty opened this issue Jan 25, 2024 · 1 comment

Comments

@ufukty
Copy link

ufukty commented Jan 25, 2024

Feature Description

I would like to request a new feature for pgFormatter: vertical alignment for segments of column definitions in table definitions. This feature would improve the readability of the SQL scripts, especially those with multiple column definitions.

Current Behavior

Currently, pgFormatter formats table definitions, but the columns and their types are not vertically aligned, which can make the scripts less readable when there are many columns. For example:

CREATE TABLE example (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

Proposed Behavior

I propose a formatting option that aligns the column names, types, and other attributes vertically. For example:

CREATE TABLE example (
    id          SERIAL PRIMARY KEY,
    name        VARCHAR(100)               NOT NULL,
    email       VARCHAR(100)               NOT NULL,
    created_at  TIMESTAMP WITH TIME ZONE   DEFAULT CURRENT_TIMESTAMP
);

This formatting makes it easier to scan and compare the columns and their attributes.

Other examples

Vertical alignment is a common feature in many code formatters for other languages and would be a valuable addition to pgFormatter for those who prioritize code readability and consistency.

  • Go fmt has this functionality. Just like
    type person struct {
        name string
        age  int
    }
  • There is an open PR on Python Yapf
@ufukty
Copy link
Author

ufukty commented Jan 25, 2024

I see this extension uses darold/pgFormatter under. So, I've opened this feature request in that repo instead. darold/pgFormatter#331

@ufukty ufukty closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant