bravo-formatter
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -74,3 +74,4 @@ /** | ||
private showNonTabularKw; | ||
private isTabularNewlineKeyword; | ||
} | ||
export {}; |
@@ -194,2 +194,3 @@ /** | ||
// this.layout.add(WS.SPACE); | ||
this.layout.add(WS.NEWLINE, WS.INDENT); | ||
this.formatNode(node.whenKw); | ||
@@ -231,2 +232,5 @@ this.layout = this.formatSubExpression(node.condition); | ||
this.layout.indentation.increaseTopLevel(); | ||
if (this.isTabularNewlineKeyword(node.nameKw)) { | ||
this.layout.add(WS.NEWLINE, WS.INDENT); | ||
} | ||
this.layout = this.formatSubExpression(node.children); | ||
@@ -410,2 +414,3 @@ this.layout.indentation.decreaseTopLevel(); | ||
case TokenType.XOR: | ||
case TokenType.ON: | ||
return this.formatLogicalOperator(node); | ||
@@ -422,2 +427,7 @@ default: | ||
this.layout.indentation.increaseTopLevel(); | ||
// tabular style, add newline when keyword longer than 8 characters | ||
if (this.isTabularNewlineKeyword(node)) { | ||
this.layout.add(WS.NEWLINE, WS.INDENT); | ||
} | ||
} else { | ||
@@ -478,3 +488,8 @@ this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node), WS.SPACE); | ||
} | ||
// under tabular style, if keyword length longer than 8, start newline with indent for trailing identifier | ||
isTabularNewlineKeyword(node) { | ||
return this.showKw(node).length >= 8 && isTabularStyle(this.cfg); | ||
} | ||
} | ||
//# sourceMappingURL=ExpressionFormatter.js.map |
@@ -6,2 +6,3 @@ import { indentString } from './config.js'; | ||
import formatAliasPositions from './formatAliasPositions.js'; | ||
import formatCreateTypePositions from './formatCreateTypePositions.js'; | ||
import ExpressionFormatter from './ExpressionFormatter.js'; | ||
@@ -56,8 +57,15 @@ import Layout, { WS } from './Layout.js'; | ||
postFormat(query) { | ||
if (this.cfg.tabulateAlias) { | ||
query = formatAliasPositions(query); | ||
try { | ||
if (this.cfg.tabulateAlias) { | ||
query = formatAliasPositions(query); | ||
} | ||
if (this.cfg.indentStyle !== 'standard') { | ||
query = formatCreateTypePositions(query); | ||
} | ||
if (this.cfg.commaPosition === 'before' || this.cfg.commaPosition === 'tabular') { | ||
query = formatCommaPositions(query, this.cfg.commaPosition, indentString(this.cfg)); | ||
} | ||
} catch (e) { | ||
console.log('error happend in postFormat'); | ||
} | ||
if (this.cfg.commaPosition === 'before' || this.cfg.commaPosition === 'tabular') { | ||
query = formatCommaPositions(query, this.cfg.commaPosition, indentString(this.cfg)); | ||
} | ||
return query; | ||
@@ -64,0 +72,0 @@ } |
@@ -7,3 +7,4 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
// queries | ||
'WITH [RECURSIVE]', 'FROM', 'WHERE', 'GROUP BY [ALL | DISTINCT]', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'LIMIT', 'OFFSET', 'FETCH {FIRST | NEXT}', | ||
// 'WITH [RECURSIVE]', | ||
'FROM', 'WHERE', 'GROUP BY [ALL | DISTINCT]', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'LIMIT', 'OFFSET', 'FETCH {FIRST | NEXT}', | ||
// Data manipulation | ||
@@ -10,0 +11,0 @@ // - insert: |
@@ -11,3 +11,4 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
// queries | ||
'WITH', 'FROM', 'WHERE', 'PREWHERE', | ||
// 'WITH', | ||
'FROM', 'WHERE', 'PREWHERE', | ||
// 条件优先于Where | ||
@@ -19,3 +20,3 @@ 'GROUP BY', 'HAVING', 'PARTITION BY', 'ORDER BY', 'LIMIT', | ||
// - update: | ||
'SET [ROLE]', 'SET [DEFAULT] ROLE', | ||
'SET', 'SET [DEFAULT] ROLE', | ||
// Data definition | ||
@@ -39,5 +40,7 @@ 'CREATE DATABASE', 'CREATE [OR REPLACE | LIVE | WINDOW] VIEW [IF NOT EXISTS]', 'REPLACE TABLE', 'CREATE [OR REPLACE] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] DICTIONARY [IF NOT EXISTS]']); | ||
// other | ||
'ALTER', 'CREATE', '{DESCRIBE | DESC}', 'DROP', 'SHOW', | ||
'ALTER', 'CREATE', '{DESCRIBE | DESC}', 'DROP', 'SHOW', 'PARTITIONED [BY]', 'TBLPROPERTIES' | ||
// 'ENGINE', | ||
'FORMAT']); | ||
// 'FORMAT' | ||
]); | ||
const reservedSetOperations = expandPhrases(['UNION [ALL | DISTINCT]', 'EXCEPT', 'INTERSECT', 'INTO OUTFILE']); | ||
@@ -44,0 +47,0 @@ |
@@ -11,3 +11,4 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
// queries | ||
'WITH', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'SORT BY', 'CLUSTER BY', 'DISTRIBUTE BY', 'LIMIT', | ||
// 'WITH', 对齐dorado,暂时移除 | ||
'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'SORT BY', 'CLUSTER BY', 'DISTRIBUTE BY', 'LIMIT', 'SET', | ||
// Data manipulation | ||
@@ -18,4 +19,2 @@ // - insert: | ||
'INSERT INTO [TABLE]', 'VALUES', | ||
// - update: | ||
'SET', | ||
// - merge: | ||
@@ -45,3 +44,3 @@ 'MERGE INTO', 'WHEN [NOT] MATCHED [THEN]', 'UPDATE SET', 'INSERT [VALUES]', | ||
// other | ||
'ALTER', 'CREATE', 'USE', 'DESCRIBE', 'DROP', 'FETCH', 'SHOW', 'STORED AS', 'STORED BY', 'ROW FORMAT']); | ||
'ALTER', 'CREATE', 'USE', 'DESCRIBE', 'DROP', 'FETCH', 'SHOW', 'STORED AS', 'STORED BY', 'ROW FORMAT', 'TBLPROPERTIES']); | ||
const reservedSetOperations = expandPhrases(['UNION [ALL | DISTINCT]']); | ||
@@ -48,0 +47,0 @@ |
@@ -7,8 +7,8 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
// queries | ||
'WITH [RECURSIVE]', 'FROM', 'WHERE', 'GROUP BY [ALL | DISTINCT]', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'LIMIT', 'OFFSET', 'FETCH {FIRST | NEXT}', | ||
// 'WITH [RECURSIVE]', | ||
'FROM', 'WHERE', 'GROUP BY [ALL | DISTINCT]', 'HAVING', 'WINDOW', 'PARTITION BY', 'ORDER BY', 'LIMIT', 'OFFSET', 'FETCH {FIRST | NEXT}', | ||
// Data manipulation | ||
// - insert: | ||
'INSERT INTO', 'VALUES', | ||
'INSERT INTO', 'VALUES', 'SET', | ||
// - update: | ||
'SET', | ||
// Data definition | ||
@@ -15,0 +15,0 @@ 'CREATE [RECURSIVE] VIEW', 'CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE']); |
@@ -24,2 +24,3 @@ /** Token type enum for all possible Token categories */ | ||
AND = "AND", | ||
ON = "ON", | ||
OR = "OR", | ||
@@ -26,0 +27,0 @@ XOR = "XOR", |
@@ -24,2 +24,3 @@ /** Token type enum for all possible Token categories */ | ||
TokenType["AND"] = "AND"; | ||
TokenType["ON"] = "ON"; | ||
TokenType["OR"] = "OR"; | ||
@@ -89,4 +90,4 @@ TokenType["XOR"] = "XOR"; | ||
/** Checks if token is any Reserved Keyword or Clause */ | ||
export const isReserved = type => type === TokenType.RESERVED_KEYWORD || type === TokenType.RESERVED_FUNCTION_NAME || type === TokenType.RESERVED_PHRASE || type === TokenType.RESERVED_CLAUSE || type === TokenType.RESERVED_SELECT || type === TokenType.RESERVED_SET_OPERATION || type === TokenType.RESERVED_JOIN || type === TokenType.ARRAY_KEYWORD || type === TokenType.CASE || type === TokenType.END || type === TokenType.WHEN || type === TokenType.ELSE || type === TokenType.THEN || type === TokenType.LIMIT || type === TokenType.BETWEEN || type === TokenType.AND || type === TokenType.OR || type === TokenType.XOR; | ||
export const isLogicalOperator = type => type === TokenType.AND || type === TokenType.OR || type === TokenType.XOR; | ||
export const isReserved = type => type === TokenType.RESERVED_KEYWORD || type === TokenType.RESERVED_FUNCTION_NAME || type === TokenType.RESERVED_PHRASE || type === TokenType.RESERVED_CLAUSE || type === TokenType.RESERVED_SELECT || type === TokenType.RESERVED_SET_OPERATION || type === TokenType.RESERVED_JOIN || type === TokenType.ARRAY_KEYWORD || type === TokenType.CASE || type === TokenType.END || type === TokenType.WHEN || type === TokenType.ELSE || type === TokenType.THEN || type === TokenType.LIMIT || type === TokenType.BETWEEN || type === TokenType.ON || type === TokenType.AND || type === TokenType.OR || type === TokenType.XOR; | ||
export const isLogicalOperator = type => type === TokenType.AND || type === TokenType.OR || type === TokenType.XOR || type === TokenType.ON; | ||
//# sourceMappingURL=token.js.map |
@@ -91,2 +91,6 @@ import { TokenType } from './token.js'; | ||
}, { | ||
type: TokenType.ON, | ||
regex: /ON\b/iuy, | ||
text: toCanonical | ||
}, { | ||
type: TokenType.OR, | ||
@@ -93,0 +97,0 @@ regex: /OR\b/iuy, |
@@ -695,2 +695,7 @@ // Generated automatically by nearley, version 2.20.1 | ||
"name": "keyword$subexpression$1", | ||
"symbols": [lexer.has("ON") ? { | ||
type: "ON" | ||
} : ON] | ||
}, { | ||
"name": "keyword$subexpression$1", | ||
"symbols": [lexer.has("XOR") ? { | ||
@@ -697,0 +702,0 @@ type: "XOR" |
{ | ||
"name": "bravo-formatter", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "Format whitespace in a SQL query to make it more readable", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2372617
258
9563