sql-formatter
Advanced tools
Comparing version 13.1.0 to 14.0.0-beta.1
@@ -21,3 +21,3 @@ import Tokenizer from './lexer/Tokenizer.js'; | ||
const dialectFromOptions = dialectOptions => ({ | ||
tokenizer: new Tokenizer(dialectOptions.tokenizerOptions), | ||
tokenizer: new Tokenizer(dialectOptions.tokenizerOptions, dialectOptions.name), | ||
formatOptions: processDialectFormatOptions(dialectOptions.formatOptions) | ||
@@ -24,0 +24,0 @@ }); |
@@ -18,66 +18,132 @@ /** | ||
* "CREATE OR REPLACE TEMPORARY TABLE" ] | ||
* | ||
* The [] and {} parenthesis can also be nested like | ||
* | ||
* "FOR [OF {UNIQUE | MANDATORY} TABLES]" | ||
* | ||
* resulting in: | ||
* | ||
* [ "FOR", | ||
* "FOR OF UNIQUE TABLES", | ||
* "FOR OF MANDATORY TABLES" ] | ||
*/ | ||
export const expandSinglePhrase = phrase => buildCombinations(parsePhrase(phrase)).map(text => text.trim()); // This data type holds variants of a single part in whole phrase. | ||
// Corresponding to syntax as follows: | ||
// | ||
// "TABLE" --> ["TABLE"] | ||
// "[TABLE]" --> ["", "TABLE"] | ||
// "[TEMP|TEMPORARY]" --> ["", "TEMP", "TEMPORARY"] | ||
// "{TEMP|TEMPORARY}" --> ["TEMP", "TEMPORARY"] | ||
// | ||
export const expandSinglePhrase = phrase => buildCombinations(parsePhrase(phrase)).map(stripExtraWhitespace); | ||
const REQUIRED_PART = /[^[\]{}]+/y; | ||
const REQUIRED_BLOCK = /\{.*?\}/y; | ||
const OPTIONAL_BLOCK = /\[.*?\]/y; | ||
const stripExtraWhitespace = text => text.replace(/ +/g, ' ').trim(); | ||
const parsePhrase = text => { | ||
let index = 0; | ||
const result = []; | ||
const parsePhrase = text => ({ | ||
type: 'mandatory_block', | ||
items: parseAlteration(text, 0)[0] | ||
}); | ||
while (index < text.length) { | ||
// Match everything else outside of "[...]" or "{...}" blocks | ||
REQUIRED_PART.lastIndex = index; | ||
const requiredMatch = REQUIRED_PART.exec(text); | ||
const parseAlteration = (text, index, expectClosing) => { | ||
const alterations = []; | ||
if (requiredMatch) { | ||
result.push([requiredMatch[0].trim()]); | ||
index += requiredMatch[0].length; | ||
} // Match "[...]" block | ||
while (text[index]) { | ||
const [term, newIndex] = parseConcatenation(text, index); | ||
alterations.push(term); | ||
index = newIndex; | ||
if (text[index] === '|') { | ||
index++; | ||
} else if (text[index] === '}' || text[index] === ']') { | ||
if (expectClosing !== text[index]) { | ||
throw new Error(`Unbalanced parenthesis in: ${text}`); | ||
} | ||
OPTIONAL_BLOCK.lastIndex = index; | ||
const optionalBlockMatch = OPTIONAL_BLOCK.exec(text); | ||
index++; | ||
return [alterations, index]; | ||
} else if (index === text.length) { | ||
if (expectClosing) { | ||
throw new Error(`Unbalanced parenthesis in: ${text}`); | ||
} | ||
if (optionalBlockMatch) { | ||
const choices = optionalBlockMatch[0].slice(1, -1).split('|').map(s => s.trim()); | ||
result.push(['', ...choices]); | ||
index += optionalBlockMatch[0].length; | ||
} // Match "{...}" block | ||
return [alterations, index]; | ||
} else { | ||
throw new Error(`Unexpected "${text[index]}"`); | ||
} | ||
} | ||
return [alterations, index]; | ||
}; | ||
REQUIRED_BLOCK.lastIndex = index; | ||
const requiredBlockMatch = REQUIRED_BLOCK.exec(text); | ||
const parseConcatenation = (text, index) => { | ||
const items = []; | ||
if (requiredBlockMatch) { | ||
const choices = requiredBlockMatch[0].slice(1, -1).split('|').map(s => s.trim()); | ||
result.push(choices); | ||
index += requiredBlockMatch[0].length; | ||
while (true) { | ||
const [term, newIndex] = parseTerm(text, index); | ||
if (term) { | ||
items.push(term); | ||
index = newIndex; | ||
} else { | ||
break; | ||
} | ||
} | ||
if (!requiredMatch && !optionalBlockMatch && !requiredBlockMatch) { | ||
throw new Error(`Unbalanced parenthesis in: ${text}`); | ||
return items.length === 1 ? [items[0], index] : [{ | ||
type: 'concatenation', | ||
items | ||
}, index]; | ||
}; | ||
const parseTerm = (text, index) => { | ||
if (text[index] === '{') { | ||
return parseMandatoryBlock(text, index + 1); | ||
} else if (text[index] === '[') { | ||
return parseOptionalBlock(text, index + 1); | ||
} else { | ||
let word = ''; | ||
while (text[index] && /[A-Za-z0-9_ ]/.test(text[index])) { | ||
word += text[index]; | ||
index++; | ||
} | ||
return [word, index]; | ||
} | ||
}; | ||
return result; | ||
const parseMandatoryBlock = (text, index) => { | ||
const [items, newIndex] = parseAlteration(text, index, '}'); | ||
return [{ | ||
type: 'mandatory_block', | ||
items | ||
}, newIndex]; | ||
}; | ||
const buildCombinations = ([first, ...rest]) => { | ||
if (first === undefined) { | ||
return ['']; | ||
const parseOptionalBlock = (text, index) => { | ||
const [items, newIndex] = parseAlteration(text, index, ']'); | ||
return [{ | ||
type: 'optional_block', | ||
items | ||
}, newIndex]; | ||
}; | ||
const buildCombinations = node => { | ||
if (typeof node === 'string') { | ||
return [node]; | ||
} else if (node.type === 'concatenation') { | ||
return node.items.map(buildCombinations).reduce(stringCombinations, ['']); | ||
} else if (node.type === 'mandatory_block') { | ||
return node.items.flatMap(buildCombinations); | ||
} else if (node.type === 'optional_block') { | ||
return ['', ...node.items.flatMap(buildCombinations)]; | ||
} else { | ||
throw new Error(`Unknown node type: ${node}`); | ||
} | ||
}; | ||
return buildCombinations(rest).flatMap(tail => first.map(head => head.trim() + ' ' + tail.trim())); | ||
const stringCombinations = (xs, ys) => { | ||
const results = []; | ||
for (const x of xs) { | ||
for (const y of ys) { | ||
results.push(x + y); | ||
} | ||
} | ||
return results; | ||
}; | ||
//# sourceMappingURL=expandPhrases.js.map |
@@ -118,3 +118,3 @@ import { equalizeWhitespace, isMultiline, last } from '../utils.js'; | ||
this.withComments(node.array, () => { | ||
this.layout.add(node.array.type === NodeType.keyword ? this.showKw(node.array) : node.array.text); | ||
this.layout.add(node.array.type === NodeType.keyword ? this.showKw(node.array) : this.showIdentifier(node.array)); | ||
}); | ||
@@ -258,3 +258,3 @@ this.formatNode(node.parenthesis); | ||
formatIdentifier(node) { | ||
this.layout.add(node.text, WS.SPACE); | ||
this.layout.add(this.showIdentifier(node), WS.SPACE); | ||
} | ||
@@ -485,3 +485,20 @@ | ||
showIdentifier(node) { | ||
if (node.quoted) { | ||
return node.text; | ||
} else { | ||
switch (this.cfg.identifierCase) { | ||
case 'preserve': | ||
return node.text; | ||
case 'upper': | ||
return node.text.toUpperCase(); | ||
case 'lower': | ||
return node.text.toLowerCase(); | ||
} | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=ExpressionFormatter.js.map |
import { indentString } from './config.js'; | ||
import Params from './Params.js'; | ||
import { createParser } from '../parser/createParser.js'; | ||
import formatCommaPositions from './formatCommaPositions.js'; | ||
import formatAliasPositions from './formatAliasPositions.js'; | ||
import ExpressionFormatter from './ExpressionFormatter.js'; | ||
@@ -27,4 +25,3 @@ import Layout, { WS } from './Layout.js'; | ||
const formattedQuery = this.formatAst(ast); | ||
const finalQuery = this.postFormat(formattedQuery); | ||
return finalQuery.trimEnd(); | ||
return formattedQuery.trimEnd(); | ||
} | ||
@@ -58,15 +55,3 @@ | ||
postFormat(query) { | ||
if (this.cfg.tabulateAlias) { | ||
query = formatAliasPositions(query); | ||
} | ||
if (this.cfg.commaPosition === 'before' || this.cfg.commaPosition === 'tabular') { | ||
query = formatCommaPositions(query, this.cfg.commaPosition, indentString(this.cfg)); | ||
} | ||
return query; | ||
} | ||
} | ||
//# sourceMappingURL=Formatter.js.map |
@@ -49,2 +49,3 @@ import { EOF_TOKEN, isToken, TokenType } from '../../lexer/token.js'; | ||
export const bigquery = { | ||
name: 'bigquery', | ||
tokenizerOptions: { | ||
@@ -51,0 +52,0 @@ reservedSelect, |
@@ -6,3 +6,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
const reservedClauses = expandPhrases([// queries | ||
'WITH', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'PARTITION BY', 'ORDER BY [INPUT SEQUENCE]', 'FETCH FIRST', // Data modification | ||
'WITH', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'PARTITION BY', 'ORDER BY [INPUT SEQUENCE]', 'LIMIT', 'OFFSET', 'FETCH NEXT', 'FOR UPDATE [OF]', 'FOR {READ | FETCH} ONLY', 'FOR {RR | CS | UR | RS} [USE AND KEEP {SHARE | UPDATE | EXCLUSIVE} LOCKS]', 'WAIT FOR OUTCOME', 'SKIP LOCKED DATA', 'INTO', // Data modification | ||
// - insert: | ||
@@ -12,19 +12,21 @@ 'INSERT INTO', 'VALUES', // - update: | ||
'MERGE INTO', 'WHEN [NOT] MATCHED [THEN]', 'UPDATE SET', 'INSERT', // Data definition | ||
'CREATE [OR REPLACE] VIEW', 'CREATE [GLOBAL TEMPORARY] TABLE']); | ||
'CREATE [OR REPLACE] VIEW', 'CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]']); | ||
const onelineClauses = expandPhrases([// - update: | ||
'UPDATE', 'WHERE CURRENT OF', 'WITH {RR | RS | CS | UR}', // - delete: | ||
'DELETE FROM', // - drop table: | ||
'DROP TABLE [HIERARCHY]', // alter table: | ||
'ALTER TABLE', 'ADD [COLUMN]', 'DROP [COLUMN]', 'RENAME [COLUMN]', 'ALTER [COLUMN]', 'SET DATA TYPE', // for alter column | ||
'DROP TABLE [IF EXISTS]', // alter table: | ||
'ALTER TABLE', 'ADD [COLUMN]', 'DROP [COLUMN]', 'RENAME COLUMN', 'ALTER [COLUMN]', 'SET DATA TYPE', // for alter column | ||
'SET NOT NULL', // for alter column | ||
'DROP {IDENTITY | EXPRESSION | DEFAULT | NOT NULL}', // for alter column | ||
'DROP {DEFAULT | GENERATED | NOT NULL}', // for alter column | ||
// - truncate: | ||
'TRUNCATE [TABLE]', // other | ||
'SET [CURRENT] SCHEMA', 'AFTER', 'GO', // https://www.ibm.com/docs/en/db2-for-zos/11?topic=statements-list-supported | ||
'ALLOCATE CURSOR', 'ALTER DATABASE', 'ALTER FUNCTION', 'ALTER INDEX', 'ALTER MASK', 'ALTER PERMISSION', 'ALTER PROCEDURE', 'ALTER SEQUENCE', 'ALTER STOGROUP', 'ALTER TABLESPACE', 'ALTER TRIGGER', 'ALTER TRUSTED CONTEXT', 'ALTER VIEW', 'ASSOCIATE LOCATORS', 'BEGIN DECLARE SECTION', 'CALL', 'CLOSE', 'COMMIT', 'CONNECT', 'CREATE ALIAS', 'CREATE AUXILIARY TABLE', 'CREATE DATABASE', 'CREATE FUNCTION', 'CREATE GLOBAL TEMPORARY TABLE', 'CREATE INDEX', 'CREATE LOB TABLESPACE', 'CREATE MASK', 'CREATE PERMISSION', 'CREATE PROCEDURE', 'CREATE ROLE', 'CREATE SEQUENCE', 'CREATE STOGROUP', 'CREATE SYNONYM', 'CREATE TABLESPACE', 'CREATE TRIGGER', 'CREATE TRUSTED CONTEXT', 'CREATE TYPE', 'CREATE VARIABLE', 'DECLARE CURSOR', 'DECLARE GLOBAL TEMPORARY TABLE', 'DECLARE STATEMENT', 'DECLARE TABLE', 'DECLARE VARIABLE', 'DESCRIBE CURSOR', 'DESCRIBE INPUT', 'DESCRIBE OUTPUT', 'DESCRIBE PROCEDURE', 'DESCRIBE TABLE', 'DROP', 'END DECLARE SECTION', 'EXCHANGE', 'EXECUTE', 'EXECUTE IMMEDIATE', 'EXPLAIN', 'FETCH', 'FREE LOCATOR', 'GET DIAGNOSTICS', 'GRANT', 'HOLD LOCATOR', 'INCLUDE', 'LABEL', 'LOCK TABLE', 'OPEN', 'PREPARE', 'REFRESH', 'RELEASE', 'RELEASE SAVEPOINT', 'RENAME', 'REVOKE', 'ROLLBACK', 'SAVEPOINT', 'SELECT INTO', 'SET CONNECTION', 'SET CURRENT ACCELERATOR', 'SET CURRENT APPLICATION COMPATIBILITY', 'SET CURRENT APPLICATION ENCODING SCHEME', 'SET CURRENT DEBUG MODE', 'SET CURRENT DECFLOAT ROUNDING MODE', 'SET CURRENT DEGREE', 'SET CURRENT EXPLAIN MODE', 'SET CURRENT GET_ACCEL_ARCHIVE', 'SET CURRENT LOCALE LC_CTYPE', 'SET CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION', 'SET CURRENT OPTIMIZATION HINT', 'SET CURRENT PACKAGE PATH', 'SET CURRENT PACKAGESET', 'SET CURRENT PRECISION', 'SET CURRENT QUERY ACCELERATION', 'SET CURRENT QUERY ACCELERATION WAITFORDATA', 'SET CURRENT REFRESH AGE', 'SET CURRENT ROUTINE VERSION', 'SET CURRENT RULES', 'SET CURRENT SQLID', 'SET CURRENT TEMPORAL BUSINESS_TIME', 'SET CURRENT TEMPORAL SYSTEM_TIME', 'SET ENCRYPTION PASSWORD', 'SET PATH', 'SET SESSION TIME ZONE', 'SIGNAL', 'VALUES INTO', 'WHENEVER']); | ||
'TRUNCATE [TABLE]', // https://www.ibm.com/docs/en/db2/11.5?topic=s-statements | ||
'ALLOCATE', 'ALTER AUDIT POLICY', 'ALTER BUFFERPOOL', 'ALTER DATABASE PARTITION GROUP', 'ALTER DATABASE', 'ALTER EVENT MONITOR', 'ALTER FUNCTION', 'ALTER HISTOGRAM TEMPLATE', 'ALTER INDEX', 'ALTER MASK', 'ALTER METHOD', 'ALTER MODULE', 'ALTER NICKNAME', 'ALTER PACKAGE', 'ALTER PERMISSION', 'ALTER PROCEDURE', 'ALTER SCHEMA', 'ALTER SECURITY LABEL COMPONENT', 'ALTER SECURITY POLICY', 'ALTER SEQUENCE', 'ALTER SERVER', 'ALTER SERVICE CLASS', 'ALTER STOGROUP', 'ALTER TABLESPACE', 'ALTER THRESHOLD', 'ALTER TRIGGER', 'ALTER TRUSTED CONTEXT', 'ALTER TYPE', 'ALTER USAGE LIST', 'ALTER USER MAPPING', 'ALTER VIEW', 'ALTER WORK ACTION SET', 'ALTER WORK CLASS SET', 'ALTER WORKLOAD', 'ALTER WRAPPER', 'ALTER XSROBJECT', 'ALTER STOGROUP', 'ALTER TABLESPACE', 'ALTER TRIGGER', 'ALTER TRUSTED CONTEXT', 'ALTER VIEW', 'ASSOCIATE [RESULT SET] {LOCATOR | LOCATORS}', 'AUDIT', 'BEGIN DECLARE SECTION', 'CALL', 'CLOSE', 'COMMENT ON', 'COMMIT [WORK]', 'CONNECT', 'CREATE [OR REPLACE] [PUBLIC] ALIAS', 'CREATE AUDIT POLICY', 'CREATE BUFFERPOOL', 'CREATE DATABASE PARTITION GROUP', 'CREATE EVENT MONITOR', 'CREATE [OR REPLACE] FUNCTION', 'CREATE FUNCTION MAPPING', 'CREATE HISTOGRAM TEMPLATE', 'CREATE [UNIQUE] INDEX', 'CREATE INDEX EXTENSION', 'CREATE [OR REPLACE] MASK', 'CREATE [SPECIFIC] METHOD', 'CREATE [OR REPLACE] MODULE', 'CREATE [OR REPLACE] NICKNAME', 'CREATE [OR REPLACE] PERMISSION', 'CREATE [OR REPLACE] PROCEDURE', 'CREATE ROLE', 'CREATE SCHEMA', 'CREATE SECURITY LABEL [COMPONENT]', 'CREATE SECURITY POLICY', 'CREATE [OR REPLACE] SEQUENCE', 'CREATE SERVICE CLASS', 'CREATE SERVER', 'CREATE STOGROUP', 'CREATE SYNONYM', 'CREATE [LARGE | REGULAR | {SYSTEM | USER} TEMPORARY] TABLESPACE', 'CREATE THRESHOLD', 'CREATE {TRANSFORM | TRANSFORMS} FOR', 'CREATE [OR REPLACE] TRIGGER', 'CREATE TRUSTED CONTEXT', 'CREATE [OR REPLACE] TYPE', 'CREATE TYPE MAPPING', 'CREATE USAGE LIST', 'CREATE USER MAPPING FOR', 'CREATE [OR REPLACE] VARIABLE', 'CREATE WORK ACTION SET', 'CREATE WORK CLASS SET', 'CREATE WORKLOAD', 'CREATE WRAPPER', 'DECLARE', 'DECLARE GLOBAL TEMPORARY TABLE', 'DESCRIBE [INPUT | OUTPUT]', 'DISCONNECT', 'DROP [PUBLIC] ALIAS', 'DROP AUDIT POLICY', 'DROP BUFFERPOOL', 'DROP DATABASE PARTITION GROUP', 'DROP EVENT MONITOR', 'DROP [SPECIFIC] FUNCTION', 'DROP FUNCTION MAPPING', 'DROP HISTOGRAM TEMPLATE', 'DROP INDEX [EXTENSION]', 'DROP MASK', 'DROP [SPECIFIC] METHOD', 'DROP MODULE', 'DROP NICKNAME', 'DROP PACKAGE', 'DROP PERMISSION', 'DROP [SPECIFIC] PROCEDURE', 'DROP ROLE', 'DROP SCHEMA', 'DROP SECURITY LABEL [COMPONENT]', 'DROP SECURITY POLICY', 'DROP SEQUENCE', 'DROP SERVER', 'DROP SERVICE CLASS', 'DROP STOGROUP', 'DROP TABLE HIERARCHY', 'DROP {TABLESPACE | TABLESPACES}', 'DROP {TRANSFORM | TRANSFORMS}', 'DROP THRESHOLD', 'DROP TRIGGER', 'DROP TRUSTED CONTEXT', 'DROP TYPE [MAPPING]', 'DROP USAGE LIST', 'DROP USER MAPPING FOR', 'DROP VARIABLE', 'DROP VIEW [HIERARCHY]', 'DROP WORK {ACTION | CLASS} SET', 'DROP WORKLOAD', 'DROP WRAPPER', 'DROP XSROBJECT', 'END DECLARE SECTION', 'EXECUTE [IMMEDIATE]', 'EXPLAIN {PLAN [SECTION] | ALL}', 'FETCH [FROM]', 'FLUSH {BUFFERPOOL | BUFFERPOOLS} ALL', 'FLUSH EVENT MONITOR', 'FLUSH FEDERATED CACHE', 'FLUSH OPTIMIZATION PROFILE CACHE', 'FLUSH PACKAGE CACHE [DYNAMIC]', 'FLUSH AUTHENTICATION CACHE [FOR ALL]', 'FREE LOCATOR', 'GET DIAGNOSTICS', 'GOTO', 'GRANT', // TODO: lots of syntax here | ||
'INCLUDE', 'ITERATE', 'LEAVE', 'LOCK TABLE', 'LOOP', 'OPEN', 'PIPE', 'PREPARE', 'REFRESH TABLE', 'RELEASE', 'RELEASE [TO] SAVEPOINT', 'RENAME [TABLE | INDEX | STOGROUP | TABLESPACE]', 'REPEAT', 'RESIGNAL', 'RETURN', 'REVOKE', // TODO: lots of syntax here | ||
'ROLLBACK [WORK] [TO SAVEPOINT]', 'SAVEPOINT', 'SET COMPILATION ENVIRONMENT', 'SET CONNECTION', 'SET CURRENT', // TODO: bunch of syntax here | ||
'SET ENCRYPTION PASSWORD', 'SET EVENT MONITOR STATE', 'SET INTEGRITY', 'SET PASSTHRU', 'SET PATH', 'SET ROLE', 'SET SCHEMA', 'SET SERVER OPTION', 'SET {SESSION AUTHORIZATION | SESSION_USER}', 'SET USAGE LIST', 'SIGNAL', 'TRANSFER OWNERSHIP OF', 'WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}', 'WHILE']); | ||
const reservedSetOperations = expandPhrases(['UNION [ALL]', 'EXCEPT [ALL]', 'INTERSECT [ALL]']); | ||
const reservedJoins = expandPhrases(['JOIN', '{LEFT | RIGHT | FULL} [OUTER] JOIN', '{INNER | CROSS} JOIN']); | ||
const reservedPhrases = expandPhrases(['ON DELETE', 'ON UPDATE', 'SET NULL', '{ROWS | RANGE} BETWEEN']); // https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/db2/rbafzintro.htm | ||
const reservedPhrases = expandPhrases(['ON DELETE', 'ON UPDATE', 'SET NULL', '{ROWS | RANGE} BETWEEN']); | ||
export const db2 = { | ||
name: 'db2', | ||
tokenizerOptions: { | ||
@@ -38,2 +40,3 @@ reservedSelect, | ||
reservedFunctionNames: functions, | ||
extraParens: ['[]'], | ||
stringTypes: [{ | ||
@@ -49,3 +52,4 @@ quote: "''-qq", | ||
identChars: { | ||
first: '@#$' | ||
first: '@#$', | ||
rest: '@#$' | ||
}, | ||
@@ -60,3 +64,3 @@ paramTypes: { | ||
}, | ||
operators: ['**', '¬=', '¬>', '¬<', '!>', '!<', '||'] | ||
operators: ['**', '%', '|', '&', '^', '~', '¬=', '¬>', '¬<', '!>', '!<', '^=', '^>', '^<', '||', '->', '=>'] | ||
}, | ||
@@ -63,0 +67,0 @@ formatOptions: { |
import { flatKeywordList } from '../../utils.js'; | ||
export const functions = flatKeywordList({ | ||
// https://www.ibm.com/docs/en/db2-for-zos/11?topic=functions-aggregate | ||
aggregate: ['ARRAY_AGG', 'AVG', 'CORR', 'CORRELATION', 'COUNT', 'COUNT_BIG', 'COVAR_POP', 'COVARIANCE', 'COVAR', 'COVAR_SAMP', 'COVARIANCE_SAMP', 'CUME_DIST', 'GROUPING', 'LISTAGG', 'MAX', 'MEDIAN', 'MIN', 'PERCENTILE_CONT', 'PERCENTILE_DISC', 'PERCENT_RANK', 'REGR_AVGX', 'REGR_AVGY', 'REGR_COUNT', 'REGR_INTERCEPT', 'REGR_ICPT', 'REGR_R2', 'REGR_SLOPE', 'REGR_SXX', 'REGR_SXY', 'REGR_SYY', 'STDDEV_POP', 'STDDEV', 'STDDEV_SAMP', 'SUM', 'VAR_POP', 'VARIANCE', 'VAR', 'VAR_SAMP', 'VARIANCE_SAMP', 'XMLAGG'], | ||
// https://www.ibm.com/docs/en/db2-for-zos/11?topic=functions-scalar | ||
scalar: ['ABS', 'ABSVAL', 'ACOS', 'ADD_DAYS', 'ADD_MONTHS', 'ARRAY_DELETE', 'ARRAY_FIRST', 'ARRAY_LAST', 'ARRAY_NEXT', 'ARRAY_PRIOR', 'ARRAY_TRIM', 'ASCII', 'ASCII_CHR', 'ASCII_STR', 'ASCIISTR', 'ASIN', 'ATAN', 'ATANH', 'ATAN2', 'BIGINT', 'BINARY', 'BITAND', 'BITANDNOT', 'BITOR', 'BITXOR', 'BITNOT', 'BLOB', 'BTRIM', 'CARDINALITY', 'CCSID_ENCODING', 'CEILING', 'CEIL', 'CHAR', 'CHAR9', 'CHARACTER_LENGTH', 'CHAR_LENGTH', 'CHR', 'CLOB', 'COALESCE', 'COLLATION_KEY', 'COMPARE_DECFLOAT', 'CONCAT', 'CONTAINS', 'COS', 'COSH', 'DATE', 'DAY', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFWEEK_ISO', 'DAYOFYEAR', 'DAYS', 'DAYS_BETWEEN', 'DBCLOB', 'DECFLOAT', 'DECFLOAT_FORMAT', 'DECFLOAT_SORTKEY', 'DECIMAL', 'DEC', 'DECODE', 'DECRYPT_BINARY', 'DECRYPT_BIT', 'DECRYPT_CHAR', 'DECRYPT_DB', 'DECRYPT_DATAKEY_BIGINT', 'DECRYPT_DATAKEY_BIT', 'DECRYPT_DATAKEY_CLOB', 'DECRYPT_DATAKEY_DBCLOB', 'DECRYPT_DATAKEY_DECIMAL', 'DECRYPT_DATAKEY_INTEGER', 'DECRYPT_DATAKEY_VARCHAR', 'DECRYPT_DATAKEY_VARGRAPHIC', 'DEGREES', 'DIFFERENCE', 'DIGITS', 'DOUBLE_PRECISION', 'DOUBLE', 'DSN_XMLVALIDATE', 'EBCDIC_CHR', 'EBCDIC_STR', 'ENCRYPT_DATAKEY', 'ENCRYPT_TDES', 'EXP', 'EXTRACT', 'FLOAT', 'FLOOR', 'GENERATE_UNIQUE', 'GENERATE_UNIQUE_BINARY', 'GETHINT', 'GETVARIABLE', 'GRAPHIC', 'GREATEST', 'HASH', 'HASH_CRC32', 'HASH_MD5', 'HASH_SHA1', 'HASH_SHA256', 'HEX', 'HOUR', 'IDENTITY_VAL_LOCAL', 'IFNULL', 'INSERT', 'INSTR', 'INTEGER', 'INT', 'JULIAN_DAY', 'LAST_DAY', 'LCASE', 'LEAST', 'LEFT', 'LENGTH', 'LN', 'LOCATE', 'LOCATE_IN_STRING', 'LOG10', 'LOWER', 'LPAD', 'LTRIM', 'MAX', 'MAX_CARDINALITY', 'MICROSECOND', 'MIDNIGHT_SECONDS', 'MIN', 'MINUTE', 'MOD', 'MONTH', 'MONTHS_BETWEEN', 'MQREAD', 'MQREADCLOB', 'MQRECEIVE', 'MQRECEIVECLOB', 'MQSEND', 'MULTIPLY_ALT', 'NEXT_DAY', 'NEXT_MONTH', 'NORMALIZE_DECFLOAT', 'NORMALIZE_STRING', 'NULLIF', 'NVL', 'OVERLAY', 'PACK', 'POSITION', 'POSSTR', 'POWER', 'POW', 'QUANTIZE', 'QUARTER', 'RADIANS', 'RAISE_ERROR', 'RANDOM', 'RAND', 'REAL', 'REGEXP_COUNT', 'REGEXP_INSTR', 'REGEXP_LIKE', 'REGEXP_REPLACE', 'REGEXP_SUBSTR', 'REPEAT', 'REPLACE', 'RID', 'RIGHT', 'ROUND', 'ROUND_TIMESTAMP', 'ROWID', 'RPAD', 'RTRIM', 'SCORE', 'SECOND', 'SIGN', 'SIN', 'SINH', 'SMALLINT', 'SOUNDEX', 'SOAPHTTPC', 'SOAPHTTPV', 'SOAPHTTPNC', 'SOAPHTTPNV', 'SPACE', 'SQRT', 'STRIP', 'STRLEFT', 'STRPOS', 'STRRIGHT', 'SUBSTR', 'SUBSTRING', 'TAN', 'TANH', 'TIME', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIMESTAMP_FORMAT', 'TIMESTAMP_ISO', 'TIMESTAMP_TZ', 'TO_CHAR', 'TO_CLOB', 'TO_DATE', 'TO_NUMBER', 'TOTALORDER', 'TO_TIMESTAMP', 'TRANSLATE', 'TRIM', 'TRIM_ARRAY', 'TRUNCATE', 'TRUNC', 'TRUNC_TIMESTAMP', 'UCASE', 'UNICODE', 'UNICODE_STR', 'UNISTR', 'UPPER', 'VALUE', 'VARBINARY', 'VARCHAR', 'VARCHAR9', 'VARCHAR_BIT_FORMAT', 'VARCHAR_FORMAT', 'VARGRAPHIC', 'VERIFY_GROUP_FOR_USER', 'VERIFY_ROLE_FOR_USER', 'VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER', 'WEEK', 'WEEK_ISO', 'WRAP', 'XMLATTRIBUTES', 'XMLCOMMENT', 'XMLCONCAT', 'XMLDOCUMENT', 'XMLELEMENT', 'XMLFOREST', 'XMLMODIFY', 'XMLNAMESPACES', 'XMLPARSE', 'XMLPI', 'XMLQUERY', 'XMLSERIALIZE', 'XMLTEXT', 'XMLXSROBJECTID', 'XSLTRANSFORM', 'YEAR'], | ||
// https://www.ibm.com/docs/en/db2-for-zos/11?topic=functions-table | ||
table: ['ADMIN_TASK_LIST', 'ADMIN_TASK_OUTPUT', 'ADMIN_TASK_STATUS', 'BLOCKING_THREADS', 'MQREADALL', 'MQREADALLCLOB', 'MQRECEIVEALL', 'MQRECEIVEALLCLOB', 'XMLTABLE'], | ||
// https://www.ibm.com/docs/en/db2-for-zos/11?topic=functions-row | ||
row: ['UNPACK'], | ||
// https://www.ibm.com/docs/en/db2-for-zos/12?topic=expressions-olap-specification | ||
olap: ['CUME_DIST', 'PERCENT_RANK', 'RANK', 'DENSE_RANK', 'NTILE', 'LAG', 'LEAD', 'ROW_NUMBER', 'FIRST_VALUE', 'LAST_VALUE', 'NTH_VALUE', 'RATIO_TO_REPORT'], | ||
// https://www.ibm.com/docs/en/db2/11.5?topic=bif-aggregate-functions | ||
aggregate: ['ARRAY_AGG', 'AVG', 'CORRELATION', 'COUNT', 'COUNT_BIG', 'COVARIANCE', 'COVARIANCE_SAMP', 'CUME_DIST', 'GROUPING', 'LISTAGG', 'MAX', 'MEDIAN', 'MIN', 'PERCENTILE_CONT', 'PERCENTILE_DISC', 'PERCENT_RANK', 'REGR_AVGX', 'REGR_AVGY', 'REGR_COUNT', 'REGR_INTERCEPT', 'REGR_ICPT', 'REGR_R2', 'REGR_SLOPE', 'REGR_SXX', 'REGR_SXY', 'REGR_SYY', 'STDDEV', 'STDDEV_SAMP', 'SUM', 'VARIANCE', 'VARIANCE_SAMP', 'XMLAGG', 'XMLGROUP'], | ||
// https://www.ibm.com/docs/en/db2/11.5?topic=bif-scalar-functions | ||
scalar: ['ABS', 'ABSVAL', 'ACOS', 'ADD_DAYS', 'ADD_HOURS', 'ADD_MINUTES', 'ADD_MONTHS', 'ADD_SECONDS', 'ADD_YEARS', 'AGE', 'ARRAY_DELETE', 'ARRAY_FIRST', 'ARRAY_LAST', 'ARRAY_NEXT', 'ARRAY_PRIOR', 'ASCII', 'ASCII_STR', 'ASIN', 'ATAN', 'ATAN2', 'ATANH', 'BIGINT', 'BINARY', 'BITAND', 'BITANDNOT', 'BITOR', 'BITXOR', 'BITNOT', 'BLOB', 'BOOLEAN', 'BPCHAR', 'BSON_TO_JSON', 'BTRIM', 'CARDINALITY', 'CEILING', 'CEIL', 'CHAR', 'CHARACTER_LENGTH', 'CHR', 'CLOB', 'COALESCE', 'COLLATION_KEY', 'COLLATION_KEY_BIT', 'COMPARE_DECFLOAT', 'CONCAT', 'COS', 'COSH', 'COT', 'CURSOR_ROWCOUNT', 'DATAPARTITIONNUM', 'DATE', 'DATETIME', 'DATE_PART', 'DATE_TRUNC', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFWEEK_ISO', 'DAYOFYEAR', 'DAYS', 'DAYS_BETWEEN', 'DAYS_TO_END_OF_MONTH', 'DBCLOB', 'DBPARTITIONNUM', 'DECFLOAT', 'DECFLOAT_FORMAT', 'DECIMAL', 'DEC', 'DECODE', 'DECRYPT_BIN', 'DECRYPT_CHAR', 'DEGREES', 'DEREF', 'DIFFERENCE', 'DIGITS', 'DOUBLE_PRECISION', 'DOUBLE', 'EMPTY_BLOB', 'EMPTY_CLOB', 'EMPTY_DBCLOB', 'EMPTY_NCLOB', 'ENCRYPT', 'EVENT_MON_STATE', 'EXP', 'EXTRACT', 'FIRST_DAY', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FLOOR', 'FROM_UTC_TIMESTAMP', 'GENERATE_UNIQUE', 'GETHINT', 'GRAPHIC', 'GREATEST', 'HASH', 'HASH4', 'HASH8', 'HASHEDVALUE', 'HEX', 'HEXTORAW', 'HOUR', 'HOURS_BETWEEN', 'IDENTITY_VAL_LOCAL', 'IFNULL', 'INITCAP', 'INSERT', 'INSTR', 'INSTR2', 'INSTR4', 'INSTRB', 'INT', 'INTERVAL', 'INTEGER', 'INT2', 'INT4', 'INT8', 'INTNAND', 'INTNOR', 'INTNXOR', 'INTNNOT', 'ISNULL', 'JSON_ARRAY', 'JSON_OBJECT', 'JSON_QUERY', 'JSON_TO_BSON', 'JSON_VALUE', 'JULIAN_DAY', 'LAST_DAY', 'LCASE', 'LEAST', 'LEFT', 'LENGTH', 'LENGTH2', 'LENGTH4', 'LENGTHB', 'LN', 'LOCATE', 'LOCATE_IN_STRING', 'LOG10', 'LONG_VARCHAR', 'LONG_VARGRAPHIC', 'LOWER', 'LPAD', 'LTRIM', 'MAX', 'MAX_CARDINALITY', 'MICROSECOND', 'MIDNIGHT_SECONDS', 'MIN', 'MINUTE', 'MINUTES_BETWEEN', 'MOD', 'MONTH', 'MONTHNAME', 'MONTHS_BETWEEN', 'MULTIPLY_ALT', 'NCHAR', 'NCHR', 'NCLOB', 'NVARCHAR', 'NEXT_DAY', 'NEXT_MONTH', 'NEXT_QUARTER', 'NEXT_WEEK', 'NEXT_YEAR', 'NORMALIZE_DECFLOAT', 'NOW', 'NULLIF', 'NUMERIC', 'NVL', 'NVL2', 'OCTET_LENGTH', 'OVERLAY', 'PARAMETER', 'POSITION', 'POSSTR', 'POW', 'POWER', 'QUANTIZE', 'QUARTER', 'QUOTE_IDENT', 'QUOTE_LITERAL', 'RADIANS', 'RAISE_ERROR', 'RAND', 'RANDOM', 'RAWTOHEX', 'REAL', 'REC2XML', 'REGEXP_COUNT', 'REGEXP_EXTRACT', 'REGEXP_INSTR', 'REGEXP_LIKE', 'REGEXP_MATCH_COUNT', 'REGEXP_REPLACE', 'REGEXP_SUBSTR', 'REPEAT', 'REPLACE', 'RID and RID_BIT', 'RIGHT', 'ROUND', 'ROUND_TIMESTAMP', 'RPAD', 'RTRIM', 'SECLABEL', 'SECLABEL_BY_NAME', 'SECLABEL_TO_CHAR', 'SECOND', 'SECONDS_BETWEEN', 'SIGN', 'SIN', 'SINH', 'SMALLINT', 'SOUNDEX', 'SPACE', 'SQRT', 'STRIP', 'STRLEFT', 'STRPOS', 'STRRIGHT', 'SUBSTR', 'SUBSTR2', 'SUBSTR4', 'SUBSTRB', 'SUBSTRING', 'TABLE_NAME', 'TABLE_SCHEMA', 'TAN', 'TANH', 'THIS_MONTH', 'THIS_QUARTER', 'THIS_WEEK', 'THIS_YEAR', 'TIME', 'TIMESTAMP', 'TIMESTAMP_FORMAT', 'TIMESTAMP_ISO', 'TIMESTAMPDIFF', 'TIMEZONE', 'TO_CHAR', 'TO_CLOB', 'TO_DATE', 'TO_HEX', 'TO_MULTI_BYTE', 'TO_NCHAR', 'TO_NCLOB', 'TO_NUMBER', 'TO_SINGLE_BYTE', 'TO_TIMESTAMP', 'TO_UTC_TIMESTAMP', 'TOTALORDER', 'TRANSLATE', 'TRIM', 'TRIM_ARRAY', 'TRUNC_TIMESTAMP', 'TRUNCATE', 'TRUNC', 'TYPE_ID', 'TYPE_NAME', 'TYPE_SCHEMA', 'UCASE', 'UNICODE_STR', 'UPPER', 'VALUE', 'VARBINARY', 'VARCHAR', 'VARCHAR_BIT_FORMAT', 'VARCHAR_FORMAT', 'VARCHAR_FORMAT_BIT', 'VARGRAPHIC', 'VERIFY_GROUP_FOR_USER', 'VERIFY_ROLE_FOR_USER', 'VERIFY_TRUSTED_CONTEXT_ROLE_FOR_USER', 'WEEK', 'WEEK_ISO', 'WEEKS_BETWEEN', 'WIDTH_BUCKET', 'XMLATTRIBUTES', 'XMLCOMMENT', 'XMLCONCAT', 'XMLDOCUMENT', 'XMLELEMENT', 'XMLFOREST', 'XMLNAMESPACES', 'XMLPARSE', 'XMLPI', 'XMLQUERY', 'XMLROW', 'XMLSERIALIZE', 'XMLTEXT', 'XMLVALIDATE', 'XMLXSROBJECTID', 'XSLTRANSFORM', 'YEAR', 'YEARS_BETWEEN', 'YMD_BETWEEN'], | ||
// https://www.ibm.com/docs/en/db2/11.5?topic=bif-table-functions | ||
table: ['BASE_TABLE', 'JSON_TABLE', 'UNNEST', 'XMLTABLE'], | ||
// https://www.ibm.com/docs/en/db2/11.5?topic=expressions-olap-specification | ||
// Additional function names not already present in the aggregate functions list | ||
olap: ['RANK', 'DENSE_RANK', 'NTILE', 'LAG', 'LEAD', 'ROW_NUMBER', 'FIRST_VALUE', 'LAST_VALUE', 'NTH_VALUE', 'RATIO_TO_REPORT'], | ||
// Type casting | ||
@@ -14,0 +13,0 @@ cast: ['CAST'] |
import { flatKeywordList } from '../../utils.js'; | ||
export const keywords = flatKeywordList({ | ||
// https://www.ibm.com/docs/en/db2-for-zos/11?topic=words-reserved#db2z_reservedwords__newresword | ||
standard: ['ALL', 'ALLOCATE', 'ALLOW', 'ALTERAND', 'ANY', 'AS', 'ARRAY', 'ARRAY_EXISTS', 'ASENSITIVE', 'ASSOCIATE', 'ASUTIME', 'AT', 'AUDIT', 'AUX', 'AUXILIARY', 'BEFORE', 'BEGIN', 'BETWEEN', 'BUFFERPOOL', 'BY', 'CAPTURE', 'CASCADED', 'CAST', 'CCSID', 'CHARACTER', 'CHECK', 'CLONE', 'CLUSTER', 'COLLECTION', 'COLLID', 'COLUMN', 'CONDITION', 'CONNECTION', 'CONSTRAINT', 'CONTENT', 'CONTINUE', 'CREATE', 'CUBE', 'CURRENT', 'CURRENT_DATE', 'CURRENT_LC_CTYPE', 'CURRENT_PATH', 'CURRENT_SCHEMA', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRVAL', 'CURSOR', 'DATA', 'DATABASE', 'DBINFO', 'DECLARE', 'DEFAULT', 'DESCRIPTOR', 'DETERMINISTIC', 'DISABLE', 'DISALLOW', 'DISTINCT', 'DO', 'DOCUMENT', 'DSSIZE', 'DYNAMIC', 'EDITPROC', 'ELSE', 'ELSEIF', 'ENCODING', 'ENCRYPTION', 'ENDING', 'END-EXEC', 'ERASE', 'ESCAPE', 'EXCEPTION', 'EXISTS', 'EXIT', 'EXTERNAL', 'FENCED', 'FIELDPROC', 'FINAL', 'FIRST', 'FOR', 'FREE', 'FULL', 'FUNCTION', 'GENERATED', 'GET', 'GLOBAL', 'GOTO', 'GROUP', 'HANDLER', 'HOLD', 'HOURS', 'IF', 'IMMEDIATE', 'IN', 'INCLUSIVE', 'INDEX', 'INHERIT', 'INNER', 'INOUT', 'INSENSITIVE', 'INTO', 'IS', 'ISOBID', 'ITERATE', 'JAR', 'KEEP', 'KEY', 'LANGUAGE', 'LAST', 'LC_CTYPE', 'LEAVE', 'LIKE', 'LOCAL', 'LOCALE', 'LOCATOR', 'LOCATORS', 'LOCK', 'LOCKMAX', 'LOCKSIZE', 'LONG', 'LOOP', 'MAINTAINED', 'MATERIALIZED', 'MICROSECONDS', 'MINUTEMINUTES', 'MODIFIES', 'MONTHS', 'NEXT', 'NEXTVAL', 'NO', 'NONE', 'NOT', 'NULL', 'NULLS', 'NUMPARTS', 'OBID', 'OF', 'OLD', 'ON', 'OPTIMIZATION', 'OPTIMIZE', 'ORDER', 'ORGANIZATION', 'OUT', 'OUTER', 'PACKAGE', 'PARAMETER', 'PART', 'PADDED', 'PARTITION', 'PARTITIONED', 'PARTITIONING', 'PATH', 'PIECESIZE', 'PERIOD', 'PLAN', 'PRECISION', 'PREVVAL', 'PRIOR', 'PRIQTY', 'PRIVILEGES', 'PROCEDURE', 'PROGRAM', 'PSID', 'PUBLIC', 'QUERY', 'QUERYNO', 'READS', 'REFERENCES', 'RESIGNAL', 'RESTRICT', 'RESULT', 'RESULT_SET_LOCATOR', 'RETURN', 'RETURNS', 'ROLE', 'ROLLUP', 'ROUND_CEILING', 'ROUND_DOWN', 'ROUND_FLOOR', 'ROUND_HALF_DOWN', 'ROUND_HALF_EVEN', 'ROUND_HALF_UP', 'ROUND_UP', 'ROW', 'ROWSET', 'SCHEMA', 'SCRATCHPAD', 'SECONDS', 'SECQTY', 'SECURITY', 'SEQUENCE', 'SENSITIVE', 'SESSION_USER', 'SIMPLE', 'SOME', 'SOURCE', 'SPECIFIC', 'STANDARD', 'STATIC', 'STATEMENT', 'STAY', 'STOGROUP', 'STORES', 'STYLE', 'SUMMARY', 'SYNONYM', 'SYSDATE', 'SYSTEM', 'SYSTIMESTAMP', 'TABLE', 'TABLESPACE', 'THEN', 'TO', 'TRIGGER', 'TYPE', 'UNDO', 'UNIQUE', 'UNTIL', 'USER', 'USING', 'VALIDPROC', 'VARIABLE', 'VARIANT', 'VCAT', 'VERSIONING', 'VIEW', 'VOLATILE', 'VOLUMES', 'WHILE', 'WLM', 'XMLEXISTS', 'XMLCAST', 'YEARS', 'ZONE'], | ||
// These are definitely keywords, but haven't found a definite list in the docs | ||
additional: ['COMMENT'] | ||
// https://www.ibm.com/docs/en/db2/11.5?topic=sql-reserved-schema-names-reserved-words | ||
standard: ['ACTIVATE', 'ADD', 'AFTER', 'ALIAS', 'ALL', 'ALLOCATE', 'ALLOW', 'ALTER', 'AND', 'ANY', 'AS', 'ASENSITIVE', 'ASSOCIATE', 'ASUTIME', 'AT', 'ATTRIBUTES', 'AUDIT', 'AUTHORIZATION', 'AUX', 'AUXILIARY', 'BEFORE', 'BEGIN', 'BETWEEN', 'BINARY', 'BUFFERPOOL', 'BY', 'CACHE', 'CALL', 'CALLED', 'CAPTURE', 'CARDINALITY', 'CASCADED', 'CASE', 'CAST', 'CCSID', 'CHAR', 'CHARACTER', 'CHECK', 'CLONE', 'CLOSE', 'CLUSTER', 'COLLECTION', 'COLLID', 'COLUMN', 'COMMENT', 'COMMIT', 'CONCAT', 'CONDITION', 'CONNECT', 'CONNECTION', 'CONSTRAINT', 'CONTAINS', 'CONTINUE', 'COUNT', 'COUNT_BIG', 'CREATE', 'CROSS', 'CURRENT', 'CURRENT_DATE', 'CURRENT_LC_CTYPE', 'CURRENT_PATH', 'CURRENT_SCHEMA', 'CURRENT_SERVER', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_TIMEZONE', 'CURRENT_USER', 'CURSOR', 'CYCLE', 'DATA', 'DATABASE', 'DATAPARTITIONNAME', 'DATAPARTITIONNUM', 'DATE', 'DAY', 'DAYS', 'DB2GENERAL', 'DB2GENRL', 'DB2SQL', 'DBINFO', 'DBPARTITIONNAME', 'DBPARTITIONNUM', 'DEALLOCATE', 'DECLARE', 'DEFAULT', 'DEFAULTS', 'DEFINITION', 'DELETE', 'DENSERANK', 'DENSE_RANK', 'DESCRIBE', 'DESCRIPTOR', 'DETERMINISTIC', 'DIAGNOSTICS', 'DISABLE', 'DISALLOW', 'DISCONNECT', 'DISTINCT', 'DO', 'DOCUMENT', 'DOUBLE', 'DROP', 'DSSIZE', 'DYNAMIC', 'EACH', 'EDITPROC', 'ELSE', 'ELSEIF', 'ENABLE', 'ENCODING', 'ENCRYPTION', 'END', 'END-EXEC', 'ENDING', 'ERASE', 'ESCAPE', 'EVERY', 'EXCEPT', 'EXCEPTION', 'EXCLUDING', 'EXCLUSIVE', 'EXECUTE', 'EXISTS', 'EXIT', 'EXPLAIN', 'EXTENDED', 'EXTERNAL', 'EXTRACT', 'FENCED', 'FETCH', 'FIELDPROC', 'FILE', 'FINAL', 'FIRST1', 'FOR', 'FOREIGN', 'FREE', 'FROM', 'FULL', 'FUNCTION', 'GENERAL', 'GENERATED', 'GET', 'GLOBAL', 'GO', 'GOTO', 'GRANT', 'GRAPHIC', 'GROUP', 'HANDLER', 'HASH', 'HASHED_VALUE', 'HAVING', 'HINT', 'HOLD', 'HOUR', 'HOURS', 'IDENTITY', 'IF', 'IMMEDIATE', 'IMPORT', 'IN', 'INCLUDING', 'INCLUSIVE', 'INCREMENT', 'INDEX', 'INDICATOR', 'INDICATORS', 'INF', 'INFINITY', 'INHERIT', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INTEGRITY', 'INTERSECT', 'INTO', 'IS', 'ISNULL', 'ISOBID', 'ISOLATION', 'ITERATE', 'JAR', 'JAVA', 'JOIN', 'KEEP', 'KEY', 'LABEL', 'LANGUAGE', 'LAST3', 'LATERAL', 'LC_CTYPE', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINKTYPE', 'LOCAL', 'LOCALDATE', 'LOCALE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATOR', 'LOCATORS', 'LOCK', 'LOCKMAX', 'LOCKSIZE', 'LONG', 'LOOP', 'MAINTAINED', 'MATERIALIZED', 'MAXVALUE', 'MICROSECOND', 'MICROSECONDS', 'MINUTE', 'MINUTES', 'MINVALUE', 'MODE', 'MODIFIES', 'MONTH', 'MONTHS', 'NAN', 'NEW', 'NEW_TABLE', 'NEXTVAL', 'NO', 'NOCACHE', 'NOCYCLE', 'NODENAME', 'NODENUMBER', 'NOMAXVALUE', 'NOMINVALUE', 'NONE', 'NOORDER', 'NORMALIZED', 'NOT2', 'NOTNULL', 'NULL', 'NULLS', 'NUMPARTS', 'OBID', 'OF', 'OFF', 'OFFSET', 'OLD', 'OLD_TABLE', 'ON', 'OPEN', 'OPTIMIZATION', 'OPTIMIZE', 'OPTION', 'OR', 'ORDER', 'OUT', 'OUTER', 'OVER', 'OVERRIDING', 'PACKAGE', 'PADDED', 'PAGESIZE', 'PARAMETER', 'PART', 'PARTITION', 'PARTITIONED', 'PARTITIONING', 'PARTITIONS', 'PASSWORD', 'PATH', 'PERCENT', 'PIECESIZE', 'PLAN', 'POSITION', 'PRECISION', 'PREPARE', 'PREVVAL', 'PRIMARY', 'PRIQTY', 'PRIVILEGES', 'PROCEDURE', 'PROGRAM', 'PSID', 'PUBLIC', 'QUERY', 'QUERYNO', 'RANGE', 'RANK', 'READ', 'READS', 'RECOVERY', 'REFERENCES', 'REFERENCING', 'REFRESH', 'RELEASE', 'RENAME', 'REPEAT', 'RESET', 'RESIGNAL', 'RESTART', 'RESTRICT', 'RESULT', 'RESULT_SET_LOCATOR', 'RETURN', 'RETURNS', 'REVOKE', 'RIGHT', 'ROLE', 'ROLLBACK', 'ROUND_CEILING', 'ROUND_DOWN', 'ROUND_FLOOR', 'ROUND_HALF_DOWN', 'ROUND_HALF_EVEN', 'ROUND_HALF_UP', 'ROUND_UP', 'ROUTINE', 'ROW', 'ROWNUMBER', 'ROWS', 'ROWSET', 'ROW_NUMBER', 'RRN', 'RUN', 'SAVEPOINT', 'SCHEMA', 'SCRATCHPAD', 'SCROLL', 'SEARCH', 'SECOND', 'SECONDS', 'SECQTY', 'SECURITY', 'SELECT', 'SENSITIVE', 'SEQUENCE', 'SESSION', 'SESSION_USER', 'SET', 'SIGNAL', 'SIMPLE', 'SNAN', 'SOME', 'SOURCE', 'SPECIFIC', 'SQL', 'SQLID', 'STACKED', 'STANDARD', 'START', 'STARTING', 'STATEMENT', 'STATIC', 'STATMENT', 'STAY', 'STOGROUP', 'STORES', 'STYLE', 'SUBSTRING', 'SUMMARY', 'SYNONYM', 'SYSFUN', 'SYSIBM', 'SYSPROC', 'SYSTEM', 'SYSTEM_USER', 'TABLE', 'TABLESPACE', 'THEN', 'TIME', 'TIMESTAMP', 'TO', 'TRANSACTION', 'TRIGGER', 'TRIM', 'TRUNCATE', 'TYPE', 'UNDO', 'UNION', 'UNIQUE', 'UNTIL', 'UPDATE', 'USAGE', 'USER', 'USING', 'VALIDPROC', 'VALUE', 'VALUES', 'VARIABLE', 'VARIANT', 'VCAT', 'VERSION', 'VIEW', 'VOLATILE', 'VOLUMES', 'WHEN', 'WHENEVER', 'WHERE', 'WHILE', 'WITH', 'WITHOUT', 'WLM', 'WRITE', 'XMLELEMENT', 'XMLEXISTS', 'XMLNAMESPACES', 'YEAR', 'YEARS'] | ||
}); | ||
//# sourceMappingURL=db2.keywords.js.map |
@@ -6,3 +6,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
const reservedClauses = expandPhrases([// queries | ||
'WITH', 'INTO', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'PARTITION BY', 'ORDER [SIBLINGS] BY [INPUT SEQUENCE]', 'OFFSET', 'FETCH {FIRST | NEXT}', 'LIMIT', 'FOR UPDATE [OF]', 'FOR READ ONLY', 'OPTIMIZE FOR', // Data modification | ||
'WITH [RECURSIVE]', 'INTO', 'FROM', 'WHERE', 'GROUP BY', 'HAVING', 'PARTITION BY', 'ORDER [SIBLINGS] BY [INPUT SEQUENCE]', 'LIMIT', 'OFFSET', 'FETCH {FIRST | NEXT}', 'FOR UPDATE [OF]', 'FOR READ ONLY', 'OPTIMIZE FOR', // Data modification | ||
// - insert: | ||
@@ -18,3 +18,3 @@ 'INSERT INTO', 'VALUES', // - update: | ||
'DROP TABLE', // alter table: | ||
'ALTER TABLE', 'ADD [COLUMN]', 'ALTER [COLUMN]', 'DROP [COLUMN]', 'RENAME [COLUMN]', 'SET DATA TYPE', // for alter column | ||
'ALTER TABLE', 'ADD [COLUMN]', 'ALTER [COLUMN]', 'DROP [COLUMN]', 'SET DATA TYPE', // for alter column | ||
'SET {GENERATED ALWAYS | GENERATED BY DEFAULT}', // for alter column | ||
@@ -29,8 +29,9 @@ 'SET NOT NULL', // for alter column | ||
'ALLOCATE CURSOR', 'ALLOCATE [SQL] DESCRIPTOR [LOCAL | GLOBAL] SQL', 'ALTER [SPECIFIC] {FUNCTION | PROCEDURE}', 'ALTER {MASK | PERMISSION | SEQUENCE | TRIGGER}', 'ASSOCIATE [RESULT SET] {LOCATOR | LOCATORS}', 'BEGIN DECLARE SECTION', 'CALL', 'CLOSE', 'COMMENT ON {ALIAS | COLUMN | CONSTRAINT | INDEX | MASK | PACKAGE | PARAMETER | PERMISSION | SEQUENCE | TABLE | TRIGGER | VARIABLE | XSROBJECT}', 'COMMENT ON [SPECIFIC] {FUNCTION | PROCEDURE | ROUTINE}', 'COMMENT ON PARAMETER SPECIFIC {FUNCTION | PROCEDURE | ROUTINE}', 'COMMENT ON [TABLE FUNCTION] RETURN COLUMN', 'COMMENT ON [TABLE FUNCTION] RETURN COLUMN SPECIFIC [PROCEDURE | ROUTINE]', 'COMMIT [WORK] [HOLD]', 'CONNECT [TO | RESET] USER', 'CREATE [OR REPLACE] {ALIAS | FUNCTION | MASK | PERMISSION | PROCEDURE | SEQUENCE | TRIGGER | VARIABLE}', 'CREATE [ENCODED VECTOR] INDEX', 'CREATE UNIQUE [WHERE NOT NULL] INDEX', 'CREATE SCHEMA', 'CREATE TYPE', 'DEALLOCATE [SQL] DESCRIPTOR [LOCAL | GLOBAL]', 'DECLARE CURSOR', 'DECLARE GLOBAL TEMPORARY TABLE', 'DECLARE', 'DESCRIBE CURSOR', 'DESCRIBE INPUT', 'DESCRIBE [OUTPUT]', 'DESCRIBE {PROCEDURE | ROUTINE}', 'DESCRIBE TABLE', 'DISCONNECT ALL [SQL]', 'DISCONNECT [CURRENT]', 'DROP {ALIAS | INDEX | MASK | PACKAGE | PERMISSION | SCHEMA | SEQUENCE | TABLE | TYPE | VARIABLE | XSROBJECT} [IF EXISTS]', 'DROP [SPECIFIC] {FUNCTION | PROCEDURE | ROUTINE} [IF EXISTS]', 'END DECLARE SECTION', 'EXECUTE [IMMEDIATE]', // 'FETCH {NEXT | PRIOR | FIRST | LAST | BEFORE | AFTER | CURRENT} [FROM]', | ||
'FREE LOCATOR', 'GET [SQL] DESCRIPTOR [LOCAL | GLOBAL]', 'GET [CURRENT | STACKED] DIAGNOSTICS', 'GRANT {ALL [PRIVILEGES] | ALTER | EXECUTE} ON {FUNCTION | PROCEDURE | ROUTINE | PACKAGE | SCHEMA | SEQUENCE | TABLE | TYPE | VARIABLE | XSROBJECT}', 'HOLD LOCATOR', 'INCLUDE', 'LABEL ON {ALIAS | COLUMN | CONSTRAINT | INDEX | MASK | PACKAGE | PERMISSION | SEQUENCE | TABLE | TRIGGER | VARIABLE | XSROBJECT}', 'LABEL ON [SPECIFIC] {FUNCTION | PROCEDURE | ROUTINE}', 'LOCK TABLE', 'OPEN', 'PREPARE', 'REFRESH TABLE', 'RELEASE', 'RELEASE [TO] SAVEPOINT', 'RENAME [TABLE | INDEX] TO', 'REVOKE {ALL [PRIVILEGES] | ALTER | EXECUTE} ON {FUNCTION | PROCEDURE | ROUTINE | PACKAGE | SCHEMA | SEQUENCE | TABLE | TYPE | VARIABLE | XSROBJECT}', 'ROLLBACK [WORK] [HOLD | TO SAVEPOINT]', 'SAVEPOINT', 'SET CONNECTION', 'SET CURRENT {DEBUG MODE | DECFLOAT ROUNDING MODE | DEGREE | IMPLICIT XMLPARSE OPTION | TEMPORAL SYSTEM_TIME}', 'SET [SQL] DESCRIPTOR [LOCAL | GLOBAL]', 'SET ENCRYPTION PASSWORD', 'SET OPTION', 'SET {[CURRENT [FUNCTION]] PATH | CURRENT_PATH}', 'SET RESULT SETS [WITH RETURN [TO CALLER | TO CLIENT]', 'SET SESSION AUTHORIZATION', 'SET SESSION_USER', 'SET TRANSACTION', 'SIGNAL SQLSTATE [VALUE]', 'TAG', 'TRANSFER OWNERSHIP OF', 'WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}']); | ||
'FREE LOCATOR', 'GET [SQL] DESCRIPTOR [LOCAL | GLOBAL]', 'GET [CURRENT | STACKED] DIAGNOSTICS', 'GRANT {ALL [PRIVILEGES] | ALTER | EXECUTE} ON {FUNCTION | PROCEDURE | ROUTINE | PACKAGE | SCHEMA | SEQUENCE | TABLE | TYPE | VARIABLE | XSROBJECT}', 'HOLD LOCATOR', 'INCLUDE', 'LABEL ON {ALIAS | COLUMN | CONSTRAINT | INDEX | MASK | PACKAGE | PERMISSION | SEQUENCE | TABLE | TRIGGER | VARIABLE | XSROBJECT}', 'LABEL ON [SPECIFIC] {FUNCTION | PROCEDURE | ROUTINE}', 'LOCK TABLE', 'OPEN', 'PREPARE', 'REFRESH TABLE', 'RELEASE', 'RELEASE [TO] SAVEPOINT', 'RENAME [TABLE | INDEX] TO', 'REVOKE {ALL [PRIVILEGES] | ALTER | EXECUTE} ON {FUNCTION | PROCEDURE | ROUTINE | PACKAGE | SCHEMA | SEQUENCE | TABLE | TYPE | VARIABLE | XSROBJECT}', 'ROLLBACK [WORK] [HOLD | TO SAVEPOINT]', 'SAVEPOINT', 'SET CONNECTION', 'SET CURRENT {DEBUG MODE | DECFLOAT ROUNDING MODE | DEGREE | IMPLICIT XMLPARSE OPTION | TEMPORAL SYSTEM_TIME}', 'SET [SQL] DESCRIPTOR [LOCAL | GLOBAL]', 'SET ENCRYPTION PASSWORD', 'SET OPTION', 'SET {[CURRENT [FUNCTION]] PATH | CURRENT_PATH}', 'SET RESULT SETS [WITH RETURN [TO CALLER | TO CLIENT]]', 'SET SESSION AUTHORIZATION', 'SET SESSION_USER', 'SET TRANSACTION', 'SIGNAL SQLSTATE [VALUE]', 'TAG', 'TRANSFER OWNERSHIP OF', 'WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}']); | ||
const reservedSetOperations = expandPhrases(['UNION [ALL]', 'EXCEPT [ALL]', 'INTERSECT [ALL]']); | ||
const reservedJoins = expandPhrases(['JOIN', '{LEFT | RIGHT | FULL} [OUTER] JOIN', '{LEFT | RIGHT } EXCEPTION JOIN', '{INNER | CROSS} JOIN']); | ||
const reservedJoins = expandPhrases(['JOIN', '{LEFT | RIGHT | FULL} [OUTER] JOIN', '[LEFT | RIGHT] EXCEPTION JOIN', '{INNER | CROSS} JOIN']); | ||
const reservedPhrases = expandPhrases(['ON DELETE', 'ON UPDATE', 'SET NULL', '{ROWS | RANGE} BETWEEN']); // https://www.ibm.com/docs/en/i/7.5?topic=reference-sql | ||
export const db2i = { | ||
name: 'db2i', | ||
tokenizerOptions: { | ||
@@ -44,5 +45,7 @@ reservedSelect, | ||
reservedFunctionNames: functions, | ||
nestedBlockComments: true, | ||
extraParens: ['[]'], | ||
stringTypes: [{ | ||
quote: "''-qq", | ||
prefixes: ['G', 'N', 'U&'] | ||
prefixes: ['G', 'N'] | ||
}, { | ||
@@ -55,3 +58,4 @@ quote: "''-raw", | ||
identChars: { | ||
first: '@#$' | ||
first: '@#$', | ||
rest: '@#$' | ||
}, | ||
@@ -66,3 +70,3 @@ paramTypes: { | ||
}, | ||
operators: ['**', '¬=', '¬>', '¬<', '!>', '!<', '||'] | ||
operators: ['**', '¬=', '¬>', '¬<', '!>', '!<', '||', '=>'] | ||
}, | ||
@@ -69,0 +73,0 @@ formatOptions: { |
@@ -31,2 +31,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const hive = { | ||
name: 'hive', | ||
tokenizerOptions: { | ||
@@ -33,0 +34,0 @@ reservedSelect, |
@@ -28,2 +28,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const mariadb = { | ||
name: 'mariadb', | ||
tokenizerOptions: { | ||
@@ -30,0 +31,0 @@ reservedSelect, |
@@ -28,2 +28,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const mysql = { | ||
name: 'mysql', | ||
tokenizerOptions: { | ||
@@ -30,0 +31,0 @@ reservedSelect, |
@@ -23,2 +23,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const n1ql = { | ||
name: 'n1ql', | ||
tokenizerOptions: { | ||
@@ -25,0 +26,0 @@ reservedSelect, |
@@ -26,2 +26,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const plsql = { | ||
name: 'plsql', | ||
tokenizerOptions: { | ||
@@ -28,0 +29,0 @@ reservedSelect, |
@@ -27,6 +27,7 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
const reservedPhrases = expandPhrases(['ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', '{ROWS | RANGE | GROUPS} BETWEEN', // https://www.postgresql.org/docs/current/datatype-datetime.html | ||
'{TIMESTAMP | TIME} {WITH | WITHOUT} TIME ZONE', // comparison operator | ||
'[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE', // comparison operator | ||
'IS [NOT] DISTINCT FROM']); // https://www.postgresql.org/docs/14/index.html | ||
export const postgresql = { | ||
name: 'postgresql', | ||
tokenizerOptions: { | ||
@@ -33,0 +34,0 @@ reservedSelect, |
@@ -28,2 +28,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const redshift = { | ||
name: 'redshift', | ||
tokenizerOptions: { | ||
@@ -30,0 +31,0 @@ reservedSelect, |
@@ -25,2 +25,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const singlestoredb = { | ||
name: 'singlestoredb', | ||
tokenizerOptions: { | ||
@@ -27,0 +28,0 @@ reservedSelect, |
@@ -42,2 +42,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const snowflake = { | ||
name: 'snowflake', | ||
tokenizerOptions: { | ||
@@ -44,0 +45,0 @@ reservedSelect, |
@@ -8,4 +8,5 @@ import { flatKeywordList } from '../../utils.js'; | ||
// These are definitely keywords, but haven't found a definite list in the docs | ||
additional: ['COMMENT'] | ||
additional: ['COMMENT'], | ||
datatypes: ['NUMBER', 'DECIMAL', 'NUMERIC', 'INT', 'INTEGER', 'BIGINT', 'SMALLINT', 'TINYINT', 'BYTEINT', 'FLOAT', 'FLOAT4', 'FLOAT8', 'DOUBLE', 'DOUBLE PRECISION', 'REAL', 'VARCHAR', 'CHAR', 'CHARACTER', 'STRING', 'TEXT', 'BINARY', 'VARBINARY', 'BOOLEAN', 'DATE', 'DATETIME', 'TIME', 'TIMESTAMP', 'TIMESTAMP_LTZ', 'TIMESTAMP_NTZ', 'TIMESTAMP', 'TIMESTAMP_TZ', 'VARIANT', 'OBJECT', 'ARRAY', 'GEOGRAPHY', 'GEOMETRY'] | ||
}); | ||
//# sourceMappingURL=snowflake.keywords.js.map |
@@ -29,2 +29,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const spark = { | ||
name: 'spark', | ||
tokenizerOptions: { | ||
@@ -31,0 +32,0 @@ reservedSelect, |
@@ -26,2 +26,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const sql = { | ||
name: 'sql', | ||
tokenizerOptions: { | ||
@@ -28,0 +29,0 @@ reservedSelect, |
@@ -23,2 +23,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const sqlite = { | ||
name: 'sqlite', | ||
tokenizerOptions: { | ||
@@ -25,0 +26,0 @@ reservedSelect, |
@@ -25,2 +25,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const transactsql = { | ||
name: 'transactsql', | ||
tokenizerOptions: { | ||
@@ -27,0 +28,0 @@ reservedSelect, |
@@ -29,2 +29,3 @@ import { expandPhrases } from '../../expandPhrases.js'; | ||
export const trino = { | ||
name: 'trino', | ||
tokenizerOptions: { | ||
@@ -31,0 +32,0 @@ reservedSelect, |
@@ -8,4 +8,5 @@ import { TokenType } from './token.js'; | ||
export default class Tokenizer { | ||
constructor(cfg) { | ||
constructor(cfg, dialectName) { | ||
this.cfg = cfg; | ||
this.dialectName = dialectName; | ||
this.rulesBeforeParams = this.buildRulesBeforeParams(cfg); | ||
@@ -17,3 +18,3 @@ this.rulesAfterParams = this.buildRulesAfterParams(cfg); | ||
const rules = [...this.rulesBeforeParams, ...this.buildParamRules(this.cfg, paramTypesOverrides), ...this.rulesAfterParams]; | ||
const tokens = new TokenizerEngine(rules).tokenize(input); | ||
const tokens = new TokenizerEngine(rules, this.dialectName).tokenize(input); | ||
return this.cfg.postProcess ? this.cfg.postProcess(tokens) : tokens; | ||
@@ -20,0 +21,0 @@ } // These rules can be cached as they only depend on |
@@ -8,4 +8,5 @@ import { lineColFromIndex } from './lineColFromIndex.js'; | ||
constructor(rules) { | ||
constructor(rules, dialectName) { | ||
this.rules = rules; | ||
this.dialectName = dialectName; | ||
} | ||
@@ -54,5 +55,13 @@ /** | ||
} = lineColFromIndex(this.input, this.index); | ||
return new Error(`Parse error: Unexpected "${text}" at line ${line} column ${col}`); | ||
return new Error(`Parse error: Unexpected "${text}" at line ${line} column ${col}.\n${this.dialectInfo()}`); | ||
} | ||
dialectInfo() { | ||
if (this.dialectName === 'sql') { | ||
return `This likely happens because you're using the default "sql" dialect.\n` + `If possible, please select a more specific dialect (like sqlite, postgresql, etc).`; | ||
} else { | ||
return `SQL dialect used: "${this.dialectName}".`; | ||
} | ||
} | ||
getWhitespace() { | ||
@@ -59,0 +68,0 @@ WHITESPACE_REGEX.lastIndex = this.index; |
@@ -438,2 +438,3 @@ // Generated automatically by nearley, version 2.20.1 | ||
type: NodeType.identifier, | ||
quoted: false, | ||
text: arrayToken.text | ||
@@ -689,2 +690,3 @@ }, { | ||
type: NodeType.identifier, | ||
quoted: token.type !== "IDENTIFIER", | ||
text: token.text | ||
@@ -691,0 +693,0 @@ }) |
@@ -31,6 +31,5 @@ import * as allDialects from './allDialects.js'; | ||
keywordCase: 'preserve', | ||
identifierCase: 'preserve', | ||
indentStyle: 'standard', | ||
logicalOperatorNewline: 'before', | ||
tabulateAlias: false, | ||
commaPosition: 'after', | ||
expressionWidth: 50, | ||
@@ -37,0 +36,0 @@ linesBetweenQueries: 1, |
@@ -5,2 +5,3 @@ import { DialectFormatOptions, ProcessedDialectFormatOptions } from './formatter/ExpressionFormatter.js'; | ||
export interface DialectOptions { | ||
name: string; | ||
tokenizerOptions: TokenizerOptions; | ||
@@ -7,0 +8,0 @@ formatOptions: DialectFormatOptions; |
@@ -18,3 +18,13 @@ /** | ||
* "CREATE OR REPLACE TEMPORARY TABLE" ] | ||
* | ||
* The [] and {} parenthesis can also be nested like | ||
* | ||
* "FOR [OF {UNIQUE | MANDATORY} TABLES]" | ||
* | ||
* resulting in: | ||
* | ||
* [ "FOR", | ||
* "FOR OF UNIQUE TABLES", | ||
* "FOR OF MANDATORY TABLES" ] | ||
*/ | ||
export declare const expandSinglePhrase: (phrase: string) => string[]; |
@@ -5,3 +5,3 @@ import { ParamItems } from './formatter/Params.js'; | ||
export declare type KeywordCase = 'preserve' | 'upper' | 'lower'; | ||
export declare type CommaPosition = 'before' | 'after' | 'tabular'; | ||
export declare type IdentifierCase = 'preserve' | 'upper' | 'lower'; | ||
export declare type LogicalOperatorNewline = 'before' | 'after'; | ||
@@ -12,6 +12,5 @@ export interface FormatOptions { | ||
keywordCase: KeywordCase; | ||
identifierCase: IdentifierCase; | ||
indentStyle: IndentStyle; | ||
logicalOperatorNewline: LogicalOperatorNewline; | ||
tabulateAlias: boolean; | ||
commaPosition: CommaPosition; | ||
expressionWidth: number; | ||
@@ -18,0 +17,0 @@ linesBetweenQueries: number; |
@@ -69,3 +69,4 @@ import { FormatOptions } from '../FormatOptions.js'; | ||
private showNonTabularKw; | ||
private showIdentifier; | ||
} | ||
export {}; |
@@ -18,3 +18,2 @@ import { FormatOptions } from '../FormatOptions.js'; | ||
private formatStatement; | ||
private postFormat; | ||
} |
@@ -6,5 +6,5 @@ export { supportedDialects, format, formatDialect } from './sqlFormatter.js'; | ||
export type { SqlLanguage, FormatOptionsWithLanguage, FormatOptionsWithDialect, } from './sqlFormatter.js'; | ||
export type { IndentStyle, KeywordCase, CommaPosition, LogicalOperatorNewline, FormatOptions, } from './FormatOptions.js'; | ||
export type { IndentStyle, KeywordCase, IdentifierCase, LogicalOperatorNewline, FormatOptions, } from './FormatOptions.js'; | ||
export type { ParamItems } from './formatter/Params.js'; | ||
export type { ParamTypes } from './lexer/TokenizerOptions.js'; | ||
export type { DialectOptions } from './dialect.js'; |
@@ -5,5 +5,6 @@ import { Token } from './token.js'; | ||
private cfg; | ||
private dialectName; | ||
private rulesBeforeParams; | ||
private rulesAfterParams; | ||
constructor(cfg: TokenizerOptions); | ||
constructor(cfg: TokenizerOptions, dialectName: string); | ||
tokenize(input: string, paramTypesOverrides: ParamTypes): Token[]; | ||
@@ -10,0 +11,0 @@ private buildRulesBeforeParams; |
@@ -14,5 +14,6 @@ import { Token, TokenType } from './token.js'; | ||
private rules; | ||
private dialectName; | ||
private input; | ||
private index; | ||
constructor(rules: TokenRule[]); | ||
constructor(rules: TokenRule[], dialectName: string); | ||
/** | ||
@@ -27,2 +28,3 @@ * Takes a SQL string and breaks it into tokens. | ||
private createParseError; | ||
private dialectInfo; | ||
private getWhitespace; | ||
@@ -29,0 +31,0 @@ private getNextToken; |
@@ -106,2 +106,3 @@ import { TokenType } from '../lexer/token.js'; | ||
type: NodeType.identifier; | ||
quoted: boolean; | ||
text: string; | ||
@@ -108,0 +109,0 @@ } |
import { FormatFn } from '../../src/sqlFormatter.js'; | ||
export default function supportsArrayLiterals(format: FormatFn): void; | ||
interface ArrayLiteralConfig { | ||
withArrayPrefix?: boolean; | ||
withoutArrayPrefix?: boolean; | ||
} | ||
export default function supportsArrayLiterals(format: FormatFn, cfg?: ArrayLiteralConfig): void; | ||
export {}; |
export class ConfigError extends Error {} | ||
export function validateConfig(cfg) { | ||
if ('multilineLists' in cfg) { | ||
throw new ConfigError('multilineLists config is no more supported.'); | ||
} | ||
const removedOptions = ['multilineLists', 'newlineBeforeOpenParen', 'newlineBeforeCloseParen', 'aliasAs', 'commaPosition', 'tabulateAlias']; | ||
if ('newlineBeforeOpenParen' in cfg) { | ||
throw new ConfigError('newlineBeforeOpenParen config is no more supported.'); | ||
for (const optionName of removedOptions) { | ||
if (optionName in cfg) { | ||
throw new ConfigError(`${optionName} config is no more supported.`); | ||
} | ||
} | ||
if ('newlineBeforeCloseParen' in cfg) { | ||
throw new ConfigError('newlineBeforeCloseParen config is no more supported.'); | ||
} | ||
if ('aliasAs' in cfg) { | ||
throw new ConfigError('aliasAs config is no more supported.'); | ||
} | ||
if (cfg.expressionWidth <= 0) { | ||
@@ -23,6 +15,2 @@ throw new ConfigError(`expressionWidth config must be positive number. Received ${cfg.expressionWidth} instead.`); | ||
if (cfg.commaPosition === 'before' && cfg.useTabs) { | ||
throw new ConfigError('commaPosition: before does not work when tabs are used for indentation.'); | ||
} | ||
if (cfg.params && !validateParams(cfg.params)) { | ||
@@ -29,0 +17,0 @@ // eslint-disable-next-line no-console |
{ | ||
"name": "sql-formatter", | ||
"version": "13.1.0", | ||
"version": "14.0.0-beta.1", | ||
"description": "Format whitespace in a SQL query to make it more readable", | ||
@@ -13,3 +13,2 @@ "license": "MIT", | ||
".": { | ||
"types": "./lib/src/index.d.ts", | ||
"import": "./lib/index.js", | ||
@@ -16,0 +15,0 @@ "require": "./dist/sql-formatter.min.cjs" |
@@ -153,6 +153,5 @@ <a href='https://github.com/sql-formatter-org/sql-formatter'><img src="static/prettier-sql-clean.svg" width="128"/></a> | ||
- [**`keywordCase`**](docs/keywordCase.md) uppercases or lowercases keywords. | ||
- [**`identifierCase`**](docs/identifierCase.md) uppercases or lowercases identifiers. (**experimental!**) | ||
- [**`indentStyle`**](docs/indentStyle.md) defines overall indentation style. | ||
- [**`logicalOperatorNewline`**](docs/logicalOperatorNewline.md) newline before or after boolean operator (AND, OR, XOR). | ||
- [**`tabulateAlias`**](docs/tabulateAlias.md) aligns column aliases vertically (**deprecated!**). | ||
- [**`commaPosition`**](docs/commaPosition.md) where to place the comma in column lists (**deprecated!**). | ||
- [**`expressionWidth`**](docs/expressionWidth.md) maximum number of characters in parenthesized expressions to be kept on single line. | ||
@@ -159,0 +158,0 @@ - [**`linesBetweenQueries`**](docs/linesBetweenQueries.md) how many newlines to insert between queries. |
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
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
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
2164510
8347
319
2
272