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: Config for uppercase / lowercase data types #653

Closed
karlhorky opened this issue Oct 31, 2023 · 3 comments · Fixed by #673
Closed

Feature Request: Config for uppercase / lowercase data types #653

karlhorky opened this issue Oct 31, 2023 · 3 comments · Fixed by #673
Labels

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Oct 31, 2023

Describe the Feature

Currently, using keywordCase: 'upper' results in

CREATE TABLE
  users (
    id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    username VARCHAR(30) NOT NULL UNIQUE,
    password_hash VARCHAR(60) NOT NULL
  );

It would be nice to have an option (eg. dataTypeCase, could default to keywordCase value for backwards compatibility) to format the data types (integer, varchar, any other data types) as lowercase, since this is the style in the PostgreSQL docs:

CREATE TABLE
  users (
    id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    username varchar(30) NOT NULL UNIQUE,
    password_hash varchar(60) NOT NULL
  );

Why do you want this feature?

This is the style in the PostgreSQL docs.

@nene
Copy link
Collaborator

nene commented Oct 31, 2023

Yeah, makes sense. Especially as some SQL dialects treat data type names as keywords and others do not. Also, this would alleviate a general problem with the formatter not understanding the context where a keyword is used.

@nene
Copy link
Collaborator

nene commented Oct 31, 2023

Also relates to: #641

@karlhorky
Copy link
Contributor Author

karlhorky commented Nov 26, 2023

Potential alternatives from #156 (comment) would be

  1. accepting an object for the option keywordCase, for granular configuration:
const options = {
  language: 'postgresql',
  keywordCase: {
    upper: true, // true: default case
    lower: ['name', 'varchar', 'integer'],
    preserve: ['in'],
  },
}
  1. an option keywordCaseIgnore (array), which would allow for more flexible customization (would not allow for same configurability, I prefer option 1)
const options = {
  language: 'postgresql',
  keywordCase: 'upper',
  keywordCaseIgnore: [
    // Avoid changing case of `name` fields in tables
    'name',
    // Avoid changing case of data types
    'varchar',
    'integer',
    // ...
  ],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants