node-sql-parser
Advanced tools
Comparing version 5.3.5 to 5.3.6
@@ -325,3 +325,3 @@ | ||
export type collate_expr = { type: 'collate'; keyword: 'collate'; collate: { symbol: '=' ; name: ident_type; value: ident_type; }} | { type: 'collate'; keyword: 'collate'; collate: { symbol: '=' | null ; name: ident_type; }}; | ||
export type collate_expr = { type: 'collate'; keyword: 'collate'; collate: { symbol: '=' | null ; name: ident_type; }}; | ||
@@ -908,7 +908,5 @@ export type column_format = { type: 'column_format'; value: 'fixed' | 'dynamic' | 'default'; }; | ||
export type cast_data_type = data_type & { quoted?: string }; | ||
export type column_item_suffix = [{ type: 'origin'; value: string; }, quoted_ident_type | column_ref]; | ||
export type column_list_item = { expr: expr; as: null; } | { type: 'cast'; expr: expr; symbol: '::'; target: cast_data_type; as?: null; } | { expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; }; | ||
export type column_list_item = { expr: expr; as: null; } | { type: 'cast'; expr: expr; symbol: '::'; target: cast_data_type[]; as?: null; } | { expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; }; | ||
@@ -1038,3 +1036,3 @@ | ||
export type window_frame_clause = string; | ||
export type window_frame_clause = { type: 'row'; expr: window_frame_following / window_frame_preceding } | binary_expr; | ||
@@ -1045,5 +1043,5 @@ export type window_frame_following = string | window_frame_current_row; | ||
export type window_frame_current_row = { type: 'single_quote_string'; value: string }; | ||
export type window_frame_current_row = { type: 'origin'; value: string }; | ||
export type window_frame_value = literal_string | literal_numeric; | ||
export type window_frame_value = { type: 'origin'; value: string } | literal_numeric; | ||
@@ -1252,2 +1250,3 @@ | ||
column: column | '*'; | ||
collate?: collate_expr; | ||
} | { | ||
@@ -1257,2 +1256,3 @@ type: 'column_ref'; | ||
column: column | '*'; | ||
collate?: collate_expr; | ||
}; | ||
@@ -1378,8 +1378,10 @@ | ||
export type cast_data_type = data_type & { quoted?: string }; | ||
export type cast_double_colon = { | ||
as?: alias_clause, | ||
symbol: '::' | 'as', | ||
target: data_type; | ||
target: cast_data_type[]; | ||
}; | ||
@@ -1386,0 +1388,0 @@ |
@@ -35,2 +35,3 @@ (function (global, factory) { | ||
if (args.separator && args.separator.delimiter) str = [str, (0, _util.literalToSQL)(args.separator.delimiter)].join(`${args.separator.symbol} `); | ||
if (args.separator && args.separator.expr) str = [str, (0, _expr.exprToSQL)(args.separator.expr)].join(' '); | ||
if (args.orderby) str = [str, (0, _expr.orderOrPartitionByToSQL)(args.orderby, 'order by')].join(' '); | ||
@@ -37,0 +38,0 @@ if (args.separator && args.separator.value) str = [str, (0, _util.toUpper)(args.separator.keyword), (0, _util.literalToSQL)(args.separator.value)].filter(_util.hasVal).join(' '); |
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "./constrain", "./expr", "./func", "./tables", "./util"], factory); | ||
define(["exports", "./collate", "./constrain", "./expr", "./func", "./tables", "./util"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("./constrain"), require("./expr"), require("./func"), require("./tables"), require("./util")); | ||
factory(exports, require("./collate"), require("./constrain"), require("./expr"), require("./func"), require("./tables"), require("./util")); | ||
} else { | ||
@@ -10,6 +10,6 @@ var mod = { | ||
}; | ||
factory(mod.exports, global.constrain, global.expr, global.func, global.tables, global.util); | ||
factory(mod.exports, global.collate, global.constrain, global.expr, global.func, global.tables, global.util); | ||
global.column = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _constrain, _expr, _func, _tables, _util) { | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _collate, _constrain, _expr, _func, _tables, _util) { | ||
"use strict"; | ||
@@ -57,2 +57,3 @@ | ||
column, | ||
collate, | ||
db, | ||
@@ -80,3 +81,3 @@ isDual, | ||
str = [`${str}${arrayIndexToSQL(array_index)}`, ...subFields].join('.'); | ||
const result = [str, (0, _expr.exprToSQL)(options), (0, _util.commonOptionConnector)('AS', _expr.exprToSQL, as)]; | ||
const result = [str, (0, _collate.collateToSQL)(collate), (0, _expr.exprToSQL)(options), (0, _util.commonOptionConnector)('AS', _expr.exprToSQL, as)]; | ||
result.push(typeof suffix === 'string' ? (0, _util.toUpper)(suffix) : (0, _expr.exprToSQL)(suffix)); | ||
@@ -83,0 +84,0 @@ result.push((0, _util.toUpper)(order_by)); |
@@ -64,3 +64,3 @@ (function (global, factory) { | ||
const { | ||
target, | ||
target: targets, | ||
expr: expression, | ||
@@ -72,29 +72,37 @@ keyword, | ||
} = expr; | ||
const { | ||
angle_brackets: angleBrackets, | ||
length, | ||
dataType, | ||
parentheses, | ||
quoted, | ||
scale, | ||
suffix: dataTypeSuffix, | ||
expr: targetExpr | ||
} = target; | ||
let str = targetExpr ? (0, _expr.exprToSQL)(targetExpr) : ''; | ||
if (length != null) str = scale ? `${length}, ${scale}` : length; | ||
if (parentheses) str = `(${str})`; | ||
if (angleBrackets) str = `<${str}>`; | ||
if (dataTypeSuffix && dataTypeSuffix.length) str += ` ${dataTypeSuffix.map(_util.literalToSQL).join(' ')}`; | ||
let prefix = (0, _expr.exprToSQL)(expression); | ||
let symbolChar = '::'; | ||
let suffix = ''; | ||
if (symbol === 'as') { | ||
prefix = `${(0, _util.toUpper)(keyword)}(${prefix}`; | ||
suffix = ')'; | ||
symbolChar = ` ${symbol.toUpperCase()} `; | ||
const result = []; | ||
for (let i = 0, len = targets.length; i < len; ++i) { | ||
const target = targets[i]; | ||
const { | ||
angle_brackets: angleBrackets, | ||
length, | ||
dataType, | ||
parentheses, | ||
quoted, | ||
scale, | ||
suffix: dataTypeSuffix, | ||
expr: targetExpr | ||
} = target; | ||
let str = targetExpr ? (0, _expr.exprToSQL)(targetExpr) : ''; | ||
if (length != null) str = scale ? `${length}, ${scale}` : length; | ||
if (parentheses) str = `(${str})`; | ||
if (angleBrackets) str = `<${str}>`; | ||
if (dataTypeSuffix && dataTypeSuffix.length) str += ` ${dataTypeSuffix.map(_util.literalToSQL).join(' ')}`; | ||
let symbolChar = '::'; | ||
let suffix = ''; | ||
const targetResult = []; | ||
if (symbol === 'as') { | ||
if (i === 0) prefix = `${(0, _util.toUpper)(keyword)}(${prefix}`; | ||
suffix = ')'; | ||
symbolChar = ` ${symbol.toUpperCase()} `; | ||
} | ||
if (i === 0) targetResult.push(prefix); | ||
const arrayDimension = arrayDimensionToSymbol(target); | ||
targetResult.push(symbolChar, quoted, dataType, quoted, arrayDimension, str, suffix); | ||
result.push(targetResult.filter(_util.hasVal).join('')); | ||
} | ||
if (alias) suffix += ` AS ${(0, _util.identifierToSql)(alias)}`; | ||
const arrayDimension = arrayDimensionToSymbol(target); | ||
const result = [prefix, symbolChar, quoted, dataType, quoted, arrayDimension, str, suffix].filter(_util.hasVal).join(''); | ||
return outParentheses ? `(${result})` : result; | ||
if (alias) result.push(` AS ${(0, _util.identifierToSql)(alias)}`); | ||
const sql = result.filter(_util.hasVal).join(''); | ||
return outParentheses ? `(${sql})` : sql; | ||
} | ||
@@ -101,0 +109,0 @@ function extractFunToSQL(stmt) { |
@@ -23,7 +23,8 @@ (function (global, factory) { | ||
expr, | ||
unit | ||
unit, | ||
suffix | ||
} = intervalExpr; | ||
const result = ['INTERVAL', (0, _expr.exprToSQL)(expr), (0, _util.toUpper)(unit)]; | ||
const result = ['INTERVAL', (0, _expr.exprToSQL)(expr), (0, _util.toUpper)(unit), (0, _expr.exprToSQL)(suffix)]; | ||
return result.filter(_util.hasVal).join(' '); | ||
} | ||
}); |
@@ -200,3 +200,3 @@ (function (global, factory) { | ||
} | ||
result.push(temporalTableToSQL(temporal_table), (0, _util.commonOptionConnector)('AS', _util.identifierToSql, as), operatorToSQL(operator)); | ||
result.push(temporalTableToSQL(temporal_table), (0, _util.commonOptionConnector)('AS', typeof as === 'string' ? _util.identifierToSql : _expr.exprToSQL, as), operatorToSQL(operator)); | ||
if (table_hint) result.push((0, _util.toUpper)(table_hint.keyword), `(${table_hint.expr.map(tableHintToSQL).filter(_util.hasVal).join(', ')})`); | ||
@@ -203,0 +203,0 @@ const tableSQL = result.filter(_util.hasVal).join(' '); |
@@ -305,2 +305,5 @@ (function (global, factory) { | ||
break; | ||
case 'unicode_string': | ||
str = `U&'${escape(value)}'`; | ||
break; | ||
default: | ||
@@ -307,0 +310,0 @@ break; |
@@ -24,2 +24,12 @@ (function (global, factory) { | ||
_exports.windowSpecificationToSQL = windowSpecificationToSQL; | ||
function windowFrameExprToSQL(windowFrameExpr) { | ||
if (!windowFrameExpr) return; | ||
const { | ||
type | ||
} = windowFrameExpr; | ||
if (type === 'rows') { | ||
return [(0, _util.toUpper)(type), (0, _expr.exprToSQL)(windowFrameExpr.expr)].filter(_util.hasVal).join(' '); | ||
} | ||
return (0, _expr.exprToSQL)(windowFrameExpr); | ||
} | ||
function windowSpecificationToSQL(windowSpec) { | ||
@@ -32,3 +42,3 @@ const { | ||
} = windowSpec; | ||
const result = [name, (0, _expr.orderOrPartitionByToSQL)(partitionby, 'partition by'), (0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'), (0, _util.toUpper)(windowFrame)]; | ||
const result = [name, (0, _expr.orderOrPartitionByToSQL)(partitionby, 'partition by'), (0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'), windowFrameExprToSQL(windowFrame)]; | ||
return result.filter(_util.hasVal).join(' '); | ||
@@ -35,0 +45,0 @@ } |
{ | ||
"name": "node-sql-parser", | ||
"version": "5.3.5", | ||
"version": "5.3.6", | ||
"description": "simple node sql parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
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 too big to display
Sorry, the diff of this file is not supported yet
89527225
51124