Skip to content

Commit

Permalink
Merge pull request #172 from chrjorgensen/feature/sql-formatter-ident…
Browse files Browse the repository at this point in the history
…ifier-case

Add SQL identifier case - new in SQL formatter 14.0.0
  • Loading branch information
worksofliam authored Nov 27, 2023
2 parents 5f03749 + 48c54a9 commit e999655
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
"default": {},
"additionalProperties": true
},
"vscode-db2i.sqlFormat.identifierCase": {
"type": "string",
"description": "SQL formatting options: Lowercase or uppercase SQL identifiers",
"default": "preserve",
"enum": ["lower", "upper", "preserve"],
"enumDescriptions": [
"Format SQL identifiers in lowercase",
"Format SQL identifiers in uppercase",
"Preserve the current formatting of SQL identifiers"
]
},
"vscode-db2i.sqlFormat.keywordCase": {
"type": "string",
"description": "SQL formatting options: Lowercase or uppercase SQL keywords",
Expand Down Expand Up @@ -598,7 +609,7 @@
"csv": "^6.1.3",
"node-fetch": "^3.3.1",
"octokit": "^2.0.14",
"sql-formatter": "^13.1.0",
"sql-formatter": "^14.0.0",
"lru-cache": "^6.0.0"
}
}
6 changes: 4 additions & 2 deletions src/database/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
import { getInstance } from "../base";
import Configuration from "../configuration";

import {format, FormatOptionsWithLanguage, KeywordCase} from "sql-formatter"
import {format, FormatOptionsWithLanguage, IdentifierCase, KeywordCase} from "sql-formatter"

export default class Statement {
static format(sql: string, options: FormatOptionsWithLanguage = {}) {
const identifierCase: IdentifierCase = <IdentifierCase>(Configuration.get(`sqlFormat.identifierCase`) || `preserve`);
const keywordCase: KeywordCase = <KeywordCase>(Configuration.get(`sqlFormat.keywordCase`) || `lower`);
return format(sql, {
...options,
language: `db2i`, // Defaults to "sql" (see the above list of supported dialects)
linesBetweenQueries: 2, // Defaults to 1
keywordCase: keywordCase
identifierCase: identifierCase,
keywordCase: keywordCase,
});
}

Expand Down

0 comments on commit e999655

Please sign in to comment.