Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-sql-parser

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sql-parser - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

185

ast/postgresql.ts

@@ -21,5 +21,5 @@

export type multiple_stmt = AstStatement<curd_stmt | crud_stmt[]>;
export type multiple_stmt = AstStatement<crud_stmt | crud_stmt[]>;
export type set_op = 'union' | 'union all' | 'union distinct' | 'intersect | 'except';
export type set_op = 'union' | 'union all' | 'union distinct' | 'intersect' | 'except';

@@ -50,3 +50,3 @@ export interface union_stmt_node extends select_stmt_node {

export type create_db_stmt = {
export type create_db_stmt_t = {
type: 'create',

@@ -59,3 +59,3 @@ keyword: 'database' | 'schema',

export type create_db_stmt = AstStatement<create_db_stmt>;
export type create_db_stmt = AstStatement<create_db_stmt_t>;

@@ -68,3 +68,3 @@ export type view_with = string;

export type create_view_stmt = {
export type create_view_stmt_t = {
type: 'create',

@@ -78,7 +78,7 @@ keyword: 'view',

select: select_stmt_nake,
with_options?: with_options,
with_options?: with_view_options,
with?: string,
}
export type create_view_stmt = AstStatement<create_view_stmt>;
export type create_view_stmt = AstStatement<create_view_stmt_t>;

@@ -91,3 +91,3 @@ export type create_aggregate_opt_required = { type: string; symbol: '='; value: expr; }[];

export type create_aggregate_stmt = {
export type create_aggregate_stmt_t = {
type: 'create',

@@ -101,3 +101,3 @@ keyword: 'aggregate',

export type create_aggregate_stmt = AstStatement<create_aggregate_stmt>;
export type create_aggregate_stmt = AstStatement<create_aggregate_stmt_t>;

@@ -110,13 +110,13 @@ export type column_data_type = { column: column_ref; definition: data_type; };

export type declare_variable_item = { keyword: 'variable'; name: string, constant?: string; datatype: data_type; collate?: collate; not_null?: string; default?: { type: 'default'; keyword: string; value: literal | expr; }; };
export type declare_variable_item = { keyword: 'variable'; name: string, constant?: string; datatype: data_type; collate?: collate_expr; not_null?: string; default?: { type: 'default'; keyword: string; value: literal | expr; }; };
export type declare_variables = declare_variable_item[];
export type declare_stmt = { type: 'declare'; declare: declare_variable_item[]; }
export type declare_stmt_t = { type: 'declare'; declare: declare_variable_item[]; }
export type declare_stmt = AstStatement<declare_stmt>;
export type declare_stmt = AstStatement<declare_stmt_t>;
export type create_func_opt = literal_string | { type: 'as'; begin?: string; declare?: declare_stmt; expr: multiple_stmt; end?: string; symbol: string; } | literal_numeric | { type: "set"; parameter: ident_name; value?: { prefix: string; expr: expr }};
export type create_function_stmt = {
export type create_function_stmt_t = {
type: 'create';

@@ -131,5 +131,5 @@ replace?: string;

export type create_function_stmt = AstStatement<create_function_stmt>;
export type create_function_stmt = AstStatement<create_function_stmt_t>;
export type create_type_stmt = {
export type create_type_stmt_t = {
type: 'create',

@@ -143,5 +143,5 @@ keyword: 'type',

export type create_type_stmt = AstStatement<create_type_stmt>;
export type create_type_stmt = AstStatement<create_type_stmt_t>;
export type create_domain_stmt = {
export type create_domain_stmt_t = {
type: 'create',

@@ -155,3 +155,3 @@ keyword: 'domain',

export type create_domain_stmt = AstStatement<create_domain_stmt>;
export type create_domain_stmt = AstStatement<create_domain_stmt_t>;

@@ -178,3 +178,3 @@ export type create_table_stmt_node = create_table_stmt_node_simple | create_table_stmt_node_like;

export type create_table_stmt = AstStatement<create_table_stmt_node> | AstStatement<create_table_stmt_node>;;
export type create_table_stmt = AstStatement<create_table_stmt_node_base & { partition_of: create_table_partition_of }> | AstStatement<create_table_stmt_node>;

@@ -245,2 +245,42 @@ export type create_sequence_stmt = {

export type for_values_item = {
type: 'for_values_item';
keyword: 'from';
from: literal_string;
to: literal_string;
} | {
type: 'for_values_item';
keyword: 'in';
in: expr_list;
} | {
type: 'for_values_item';
keyword: 'with';
modulus: literal_numeric;
remainder: literal_numeric;
};
export type for_values = {
type: 'for_values';
keyword: 'for values';
expr: for_values_item;
};
export type create_table_partition_of = {
type: 'partition_of';
keyword: 'partition of';
table: table_name;
for_values: for_values;
tablespace: ident_without_kw_type | undefined;
};
export type create_table_definition = create_definition[];

@@ -336,5 +376,5 @@

export type aggregate_signature = { name: ”*“ } | alter_func_args;
export type aggregate_signature = { name: "*" } | alter_func_args;
export type alter_func_argmode = ignore;
export type alter_func_argmode = "IN" | "OUT" | "VARIADIC";

@@ -413,6 +453,6 @@ export type alter_func_arg_item = { mode?: string; name?: string; type: data_type; default: default_arg_expr; };

keyword?: 'to' | 'as';
[key: string]: ident;
[key: string]: ident | undefined;
}
export type ALTER_RENAME = AstStatement<alter_rename>;
export type ALTER_RENAME = AstStatement<alter_rename_owner>;

@@ -675,3 +715,3 @@ export type ALTER_OWNER_TO = AstStatement<alter_rename_owner>;

export interface grant_revoke_stmt {
export interface grant_revoke_stmt_t {
type: string;

@@ -690,9 +730,9 @@ grant_option_for?: origin_str_stmt;

export type grant_revoke_stmt = AstStatement<grant_revoke_stmt> | => AstStatement<grant_revoke_stmt>;
export type grant_revoke_stmt = AstStatement<grant_revoke_stmt_t>;
export type elseif_stmt = { type: 'elseif'; boolean_expr: expr; then: curd_stmt; semicolon?: string; };
export type elseif_stmt = { type: 'elseif'; boolean_expr: expr; then: crud_stmt; semicolon?: string; };
export type elseif_stmt_list = elseif_stmt[];
export interface if_else_stmt {
export interface if_else_stmt_t {
type: 'if';

@@ -704,3 +744,3 @@ keyword: 'if';

elseif_expr: elseif_stmt[];
else_expr: curd_stmt;
else_expr: crud_stmt;
prefix: literal_string;

@@ -710,3 +750,3 @@ suffix: literal_string;

export type if_else_stmt = AstStatement<if_else_stmt>;
export type if_else_stmt = AstStatement<if_else_stmt_t>;

@@ -719,3 +759,3 @@ export type raise_level = "DEBUG" | "LOG" | "INFO" | "NOTICE" | "WARNING" | "EXCEPTION";

export interface raise_stmt {
export interface raise_stmt_t {
type: 'raise';

@@ -727,5 +767,5 @@ level?: string;

export type raise_stmt = AstStatement<raise_stmt>;
export type raise_stmt = AstStatement<raise_stmt_t>;
export interface execute_stmt {
export interface execute_stmt_t {
type: 'execute';

@@ -736,7 +776,7 @@ name: string;

export type execute_stmt = AstStatement<execute_stmt>;
export type execute_stmt = AstStatement<execute_stmt_t>;
export type for_label = { label?: string; keyword: 'for'; };
export interface for_loop_stmt {
export interface for_loop_stmt_t {
type: 'for';

@@ -749,5 +789,5 @@ label?: string

export type for_loop_stmt = AstStatement<for_loop_stmt>;
export type for_loop_stmt = AstStatement<for_loop_stmt_t>;
export interface transaction_stmt {
export interface transaction_stmt_t {
type: 'transaction';

@@ -760,3 +800,3 @@ expr: {

export type transaction_stmt = AstStatement<transaction_stmt>;
export type transaction_stmt = AstStatement<transaction_stmt_t>;

@@ -805,3 +845,3 @@ export interface select_stmt_node extends select_stmt_nake {

export type expr_item = binary_expr & { array_index: array_index };
export type expr_item = binary_column_expr & { array_index: array_index };

@@ -851,3 +891,3 @@ export type cast_data_type = data_type & { quoted?: string };

export type table_join = table_base & {join: join_op; using: ident_name[]; } | table_base & {join: join_op; on?: on_clause; } | {
expr: (union_stmt || table_ref_list) & { parentheses: true; };
expr: (union_stmt | table_ref_list) & { parentheses: true; };
as?: alias_clause;

@@ -874,2 +914,33 @@ join: join_op;

export type BINARY_OPERATORS =
| LOGIC_OPERATOR
| "OR"
| "AND"
| multiplicative_operator
| additive_operator
| arithmetic_comparison_operator
| "IN"
| "NOT IN"
| "BETWEEN"
| "NOT BETWEEN"
| "IS"
| "IS NOT"
| "LIKE"
| "@>"
| "<@"
| OPERATOR_CONCATENATION
| DOUBLE_WELL_ARROW
| WELL_ARROW
| "?"
| "?|"
| "?&"
| "#-";
export type binary_expr = {
type: "binary_expr";
operator: BINARY_OPERATORS;
left: expr;
right: expr;
};
export type or_and_expr = binary_expr;

@@ -1023,26 +1094,10 @@

export type case_when_then = { type: 'when'; cond: binary_expr; result: expr; };
export type case_when_then = { type: 'when'; cond: or_and_where_expr; result: expr; };
export type case_else = { type: 'else'; condition?: never; result: expr; };
export type _expr = logic_operator_expr | or_expr | unary_expr;
export type _expr = or_expr | unary_expr;
export type expr = _expr | union_stmt;
export type BINARY_OPERATORS = LOGIC_OPERATOR | 'OR' | 'AND' | multiplicative_operator | additive_operator
| arithmetic_comparison_operator
| 'IN' | 'NOT IN'
| 'BETWEEN' | 'NOT BETWEEN'
| 'IS' | 'IS NOT'
| 'LIKE'
| '@>' | '<@' | OPERATOR_CONCATENATION | DOUBLE_WELL_ARROW | WELL_ARROW | '?' | '?|' | '?&' | '#-'
export interface binary_expr {
type: 'binary_expr',
operator: BINARY_OPERATORS,
left: expr,
right: expr
}
export type logic_operator_expr = binary_expr;
export type UNARY_OPERATORS = '+' | '-' | 'EXISTS' | 'NOT EXISTS' | 'NULL'

@@ -1142,3 +1197,3 @@

export type column_ref_quoted = IGNORE;
export type column_ref_quoted = unknown;

@@ -1221,3 +1276,3 @@ export type column_list = column[];

export type aggr_fun_count = { type: 'aggr_func'; name: 'COUNT' | 'GROUP_CONCAT'; args:count_arg; over: over_partition } | { type: 'aggr_func'; name: 'PERCENTILE_CONT' | 'PERCENTILE_DISC'; args: literal_numeric / literal_array; within_group_orderby: order_by_clause; over?: over_partition } | { type: 'aggr_func'; name: 'MODE'; args: literal_numeric / literal_array; within_group_orderby: order_by_clause; over?: over_partition };
export type aggr_fun_count = { type: 'aggr_func'; name: 'COUNT' | 'GROUP_CONCAT'; args:count_arg; over: over_partition } | { type: 'aggr_func'; name: 'PERCENTILE_CONT' | 'PERCENTILE_DISC'; args: literal_numeric | literal_array; within_group_orderby: order_by_clause; over?: over_partition } | { type: 'aggr_func'; name: 'MODE'; args: literal_numeric | literal_array; within_group_orderby: order_by_clause; over?: over_partition };

@@ -1279,4 +1334,3 @@ export type concat_separator = { keyword: string | null; value: literal_string; };

keyword: 'cast';
...cast_double_colon;
} | {
} & cast_double_colon | ({
type: 'cast';

@@ -1286,4 +1340,3 @@ expr: literal | aggr_func | func_call | case_expr | interval_expr | column_ref | param

keyword: 'cast';
...cast_double_colon;
};
} & cast_double_colon);

@@ -1763,5 +1816,5 @@ export type signedness = KW_SIGNED | KW_UNSIGNED;

export interface proc_stmt { type: 'proc'; stmt: assign_stmt | return_stmt; vars: any }
export interface proc_stmt_t { type: 'proc'; stmt: assign_stmt | return_stmt; vars: any }
export type proc_stmt = AstStatement<proc_stmt>;
export type proc_stmt = AstStatement<proc_stmt_t>;

@@ -1792,3 +1845,3 @@ export type assign_stmt = { type: 'assign'; left: var_decl | without_prefix_var_decl; symbol: ':=' | '='; right: proc_expr; };

export type var_decl = { type: 'var'; name: string; prefix: string; suffix: string; }; | without_prefix_var_decl & { type: 'var'; prefix: string; };;
export type var_decl = { type: 'var'; name: string; prefix: string; suffix: string; } | without_prefix_var_decl & { type: 'var'; prefix: string; };

@@ -1795,0 +1848,0 @@ export type without_prefix_var_decl = { type: 'var'; prefix: string; name: ident_name; members: mem_chain; quoted: string | null } | { type: 'var'; prefix: null; name: number; members: []; quoted: null };

@@ -27,3 +27,2 @@ (function (global, factory) {

create_definitions: createDefinition,
first_after: firstAfter,
if_not_exists: ifNotExists,

@@ -34,3 +33,4 @@ keyword,

resource,
symbol
symbol,
suffix
} = expr;

@@ -73,3 +73,3 @@ let name = '';

}
const alterArray = [(0, _util.toUpper)(action), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), oldColumn && (0, _column.columnRefToSQL)(oldColumn), (0, _util.toUpper)(prefix), name && name.trim(), dataType.filter(_util.hasVal).join(' '), firstAfter && `${(0, _util.toUpper)(firstAfter.keyword)} ${(0, _column.columnRefToSQL)(firstAfter.column)}`];
const alterArray = [(0, _util.toUpper)(action), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), oldColumn && (0, _column.columnRefToSQL)(oldColumn), (0, _util.toUpper)(prefix), name && name.trim(), dataType.filter(_util.hasVal).join(' '), suffix && `${(0, _util.toUpper)(suffix.keyword)} ${(0, _column.columnRefToSQL)(suffix.expr)}`];
return alterArray.filter(_util.hasVal).join(' ');

@@ -76,0 +76,0 @@ }

(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports", "./expr"], factory);
define(["exports", "./expr", "./util"], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require("./expr"));
factory(exports, require("./expr"), require("./util"));
} else {

@@ -10,6 +10,6 @@ var mod = {

};
factory(mod.exports, global.expr);
factory(mod.exports, global.expr, global.util);
global.assign = mod.exports;
}
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr) {
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _util) {
"use strict";

@@ -32,4 +32,4 @@

const rightVal = (0, _expr.exprToSQL)(right);
return `${leftVar} ${symbol} ${rightVal}`;
return [leftVar, symbol, rightVal].filter(_util.hasVal).join(' ');
}
});

@@ -43,5 +43,21 @@ (function (global, factory) {

const escape = expr.right.escape || {};
const str = [(0, _expr.exprToSQL)(expr.left), operator, rstr, (0, _util.toUpper)(escape.type), (0, _expr.exprToSQL)(escape.value)].filter(_util.hasVal).join(' ');
return expr.parentheses ? `(${str})` : str;
const leftPart = Array.isArray(expr.left) ? expr.left.map(_expr.exprToSQL).join(', ') : (0, _expr.exprToSQL)(expr.left);
const str = [leftPart, operator, rstr, (0, _util.toUpper)(escape.type), (0, _expr.exprToSQL)(escape.value)].filter(_util.hasVal).join(' ');
const result = [expr.parentheses ? `(${str})` : str];
const {
suffix
} = expr;
if (!suffix) return result.join(' ');
for (const suffixItem of suffix) {
const {
type
} = suffixItem;
switch (type) {
case 'collate':
result.push((0, _util.commonTypeValue)(suffixItem).join(' '));
break;
}
}
return result.filter(_util.hasVal).join(' ');
}
});

@@ -38,2 +38,12 @@ (function (global, factory) {

}
function arrayIndexToSQL(arrayIndexList) {
if (!arrayIndexList || arrayIndexList.length === 0) return '';
const result = [];
for (const arrayIndex of arrayIndexList) {
let arrayIndexStr = arrayIndex.brackets ? `[${(0, _util.literalToSQL)(arrayIndex.index)}]` : `${arrayIndex.notation}${(0, _util.literalToSQL)(arrayIndex.index)}`;
if (arrayIndex.property) arrayIndexStr = `${arrayIndexStr}.${(0, _util.literalToSQL)(arrayIndex.property)}`;
result.push(arrayIndexStr);
}
return result.join('');
}
function columnRefToSQL(expr) {

@@ -48,2 +58,3 @@ const {

isDual,
notations = [],
schema,

@@ -58,11 +69,12 @@ table,

let str = column === '*' ? '*' : columnOffsetToSQL(column, isDual);
const prefix = [db, schema, table].filter(_util.hasVal).map(val => `${typeof val === 'string' ? (0, _util.identifierToSql)(val) : (0, _expr.exprToSQL)(val)}`).join('.');
if (prefix) str = `${prefix}.${str}`;
if (array_index) {
for (const arrayIndex of array_index) {
str = `${str}[${(0, _util.literalToSQL)(arrayIndex.index)}]`;
if (arrayIndex.property) str = `${str}.${(0, _util.literalToSQL)(arrayIndex.property)}`;
const prefix = [db, schema, table].filter(_util.hasVal).map(val => `${typeof val === 'string' ? (0, _util.identifierToSql)(val) : (0, _expr.exprToSQL)(val)}`);
let prefixStr = prefix[0];
if (prefixStr) {
let i = 1;
for (; i < prefix.length; ++i) {
prefixStr = `${prefixStr}${notations[i] || '.'}${prefix[i]}`;
}
str = `${prefixStr}${notations[i] || '.'}${str}`;
}
str = [str, ...subFields].join('.');
str = [`${str}${arrayIndexToSQL(array_index)}`, ...subFields].join('.');
const result = [str, (0, _util.commonOptionConnector)('AS', _expr.exprToSQL, as), arrows.map((arrow, index) => (0, _util.commonOptionConnector)(arrow, _util.literalToSQL, properties[index])).join(' ')];

@@ -212,5 +224,3 @@ if (collate) result.push((0, _util.commonTypeValue)(collate).join(' '));

if (expr.array_index && expr.type !== 'column_ref') {
for (const arrayIndex of expr.array_index) {
str = `${str}[${(0, _util.literalToSQL)(arrayIndex.index)}]`;
}
str = `${str}${arrayIndexToSQL(expr.array_index)}`;
}

@@ -217,0 +227,0 @@ return [str, asToSQL(column.as)].filter(_util.hasVal).join(' ');

@@ -39,2 +39,31 @@ (function (global, factory) {

}
function forValueItemToSQL(stmt) {
const {
keyword
} = stmt;
const result = [];
switch (keyword) {
case 'from':
result.push('FROM', `(${(0, _util.literalToSQL)(stmt.from)})`, 'TO', `(${(0, _util.literalToSQL)(stmt.to)})`);
break;
case 'in':
result.push('IN', `(${(0, _expr.exprToSQL)(stmt.in)})`);
break;
case 'with':
result.push('WITH', `(MODULUS ${(0, _util.literalToSQL)(stmt.modulus)}, REMAINDER ${(0, _util.literalToSQL)(stmt.remainder)})`);
break;
}
return result.filter(_util.hasVal).join(' ');
}
function createTablePartitionOfToSQL(stmt) {
const {
keyword,
table,
for_values: forValues,
tablespace
} = stmt;
const result = [(0, _util.toUpper)(keyword), (0, _tables.tableToSQL)(table), (0, _util.toUpper)(forValues.keyword), forValueItemToSQL(forValues.expr)];
if (tablespace) result.push('TABLESPACE', (0, _util.literalToSQL)(tablespace));
return result.filter(_util.hasVal).join(' ');
}
function createTableToSQL(stmt) {

@@ -53,2 +82,3 @@ const {

or_replace: orReplace,
partition_of: partitionOf,
query_expr: queryExpr

@@ -66,8 +96,5 @@ } = stmt;

}
if (createDefinition) {
sql.push(`(${createDefinition.map(createDefinitionToSQL).join(', ')})`);
}
if (tableOptions) {
sql.push(tableOptions.map(_tables.tableOptionToSQL).join(' '));
}
if (partitionOf) return sql.concat([createTablePartitionOfToSQL(partitionOf)]).filter(_util.hasVal).join(' ');
if (createDefinition) sql.push(`(${createDefinition.map(createDefinitionToSQL).join(', ')})`);
if (tableOptions) sql.push(tableOptions.map(_tables.tableOptionToSQL).join(' '));
sql.push((0, _util.toUpper)(ignoreReplace), (0, _util.toUpper)(as));

@@ -74,0 +101,0 @@ if (queryExpr) sql.push((0, _union.unionToSQL)(queryExpr));

@@ -45,2 +45,4 @@ (function (global, factory) {

json: _json.jsonExprToSQL,
json_object_arg: _func.jsonObjectArgToSQL,
json_visitor: _json.jsonVisitorExprToSQL,
show: _show.showToSQL,

@@ -108,2 +110,11 @@ struct: _arrayStruct.arrayStructExprToSQL,

exprToSQLConvertFn.unary_expr = unaryToSQL;
function mapObjectToSQL(mapExpr) {
const {
keyword,
expr
} = mapExpr;
const exprStr = expr.map(exprItem => [(0, _util.literalToSQL)(exprItem.key), (0, _util.literalToSQL)(exprItem.value)].join(', ')).join(', ');
return [(0, _util.toUpper)(keyword), `[${exprStr}]`].join('');
}
exprToSQLConvertFn.map_object = mapObjectToSQL;
function orderOrPartitionByToSQL(expr, prefix) {

@@ -110,0 +121,0 @@ if (!Array.isArray(expr)) return '';

@@ -24,2 +24,3 @@ (function (global, factory) {

_exports.funcToSQL = funcToSQL;
_exports.jsonObjectArgToSQL = jsonObjectArgToSQL;
_exports.lambdaToSQL = lambdaToSQL;

@@ -114,2 +115,15 @@ _exports.tablefuncFunToSQL = tablefuncFunToSQL;

}
function jsonObjectArgToSQL(argExpr) {
const {
expr
} = argExpr;
const {
key,
value,
on
} = expr;
const result = [(0, _expr.exprToSQL)(key), 'VALUE', (0, _expr.exprToSQL)(value)];
if (on) result.push('ON', 'NULL', (0, _expr.exprToSQL)(on));
return result.filter(_util.hasVal).join(' ');
}
function flattenFunToSQL(stmt) {

@@ -116,0 +130,0 @@ const {

@@ -20,2 +20,3 @@ (function (global, factory) {

_exports.jsonExprToSQL = jsonExprToSQL;
_exports.jsonVisitorExprToSQL = jsonVisitorExprToSQL;
function jsonExprToSQL(expr) {

@@ -29,2 +30,9 @@ const {

}
function jsonVisitorExprToSQL(stmt) {
const {
symbol,
expr
} = stmt;
return [symbol, (0, _expr.exprToSQL)(expr)].join('');
}
});

@@ -102,5 +102,4 @@ (function (global, factory) {

const clauses = [(0, _with.withToSQL)(withInfo), 'SELECT', (0, _util.toUpper)(asStructVal)];
clauses.push((0, _util.topToSQL)(top));
if (Array.isArray(options)) clauses.push(options.join(' '));
clauses.push(distinctToSQL(distinct), (0, _column.columnsToSQL)(columns, from));
clauses.push(distinctToSQL(distinct), (0, _util.topToSQL)(top), (0, _column.columnsToSQL)(columns, from));
const {

@@ -107,0 +106,0 @@ position

@@ -99,2 +99,31 @@ (function (global, factory) {

}
function temporalTableOptionToSQL(stmt) {
const {
keyword
} = stmt;
const result = [];
switch (keyword) {
case 'as':
result.push('AS', 'OF', (0, _expr.exprToSQL)(stmt.of));
break;
case 'from_to':
result.push('FROM', (0, _expr.exprToSQL)(stmt.from), 'TO', (0, _expr.exprToSQL)(stmt.to));
break;
case 'between_and':
result.push('BETWEEN', (0, _expr.exprToSQL)(stmt.between), 'AND', (0, _expr.exprToSQL)(stmt.and));
break;
case 'contained':
result.push('CONTAINED', 'IN', (0, _expr.exprToSQL)(stmt.in));
break;
}
return result.filter(_util.hasVal).join(' ');
}
function temporalTableToSQL(stmt) {
if (!stmt) return;
const {
keyword,
expr
} = stmt;
return [(0, _util.toUpper)(keyword), temporalTableOptionToSQL(expr)].filter(_util.hasVal).join(' ');
}
function tableToSQL(tableInfo) {

@@ -113,2 +142,3 @@ if ((0, _util.toUpper)(tableInfo.type) === 'UNNEST') return unnestToSQL(tableInfo);

tablesample,
temporal_table,
table_hint

@@ -150,3 +180,3 @@ } = tableInfo;

}
result.push((0, _util.commonOptionConnector)('AS', _util.identifierToSql, as), operatorToSQL(operator));
result.push(temporalTableToSQL(temporal_table), (0, _util.commonOptionConnector)('AS', _util.identifierToSql, as), operatorToSQL(operator));
if (table_hint) result.push((0, _util.toUpper)(table_hint.keyword), `(${table_hint.expr.map(tableHintToSQL).filter(_util.hasVal).join(', ')})`);

@@ -153,0 +183,0 @@ return result.filter(_util.hasVal).join(' ');

{
"name": "node-sql-parser",
"version": "5.0.0",
"version": "5.1.0",
"description": "simple node sql parser",

@@ -80,2 +80,3 @@ "main": "index.js",

"nyc": "15.1.0",
"pegjs": "^0.10.0",
"pegjs-loader": "^0.5.6",

@@ -99,5 +100,5 @@ "pre-commit": "^1.2.2",

"dependencies": {
"big-integer": "^1.6.48",
"@types/pegjs": "^0.10.0"
"@types/pegjs": "^0.10.0",
"big-integer": "^1.6.48"
}
}

@@ -45,11 +45,11 @@ // Type definitions for node-sql-parser 1.0

export interface Join extends BaseFrom {
join: "INNER JOIN" | "LEFT JOIN" | "RIGHT JOIN";
using?: string[];
on?: Expr;
join: "INNER JOIN" | "LEFT JOIN" | "RIGHT JOIN";
using?: string[];
on?: Expr;
}
export interface TableExpr {
expr: {
ast: Select;
},
as?: string | null;
expr: {
ast: Select;
};
as?: string | null;
}

@@ -78,3 +78,23 @@ export interface Dual {

export interface ValueExpr<T = string | number | boolean> {
type: "backticks_quote_string" | "string" | "regex_string" | "hex_string" | "full_hex_string" | "natural_string" | "bit_string" | "double_quote_string" | "single_quote_string" | "boolean" | "bool" | "null" | "star" | "param" | "origin" | "date" | "datetime" | "time" | "timestamp" | "var_string";
type:
| "backticks_quote_string"
| "string"
| "regex_string"
| "hex_string"
| "full_hex_string"
| "natural_string"
| "bit_string"
| "double_quote_string"
| "single_quote_string"
| "boolean"
| "bool"
| "null"
| "star"
| "param"
| "origin"
| "date"
| "datetime"
| "time"
| "timestamp"
| "var_string";
value: T;

@@ -109,10 +129,13 @@ }

expr: null;
args: Array<{
cond: Expr;
result: ExpressionValue;
type: "when";
} | {
result: ExpressionValue;
type: "else";
}>;
args: Array<
| {
cond: Expr;
result: ExpressionValue;
type: "when";
}
| {
result: ExpressionValue;
type: "else";
}
>;
}

@@ -127,3 +150,3 @@ export interface Cast {

suffix: unknown[];
}
};
}

@@ -142,3 +165,6 @@ export interface AggrFunc {

export type FunctionName = { schema?: { value: string, type: string } , name: ValueExpr<string>[] }
export type FunctionName = {
schema?: { value: string; type: string };
name: ValueExpr<string>[];
};
export interface Function {

@@ -159,27 +185,35 @@ type: "function";

export interface Interval {
type: "interval";
unit: string;
expr: ValueExpr & { loc?: LocationRange; }
type: "interval";
unit: string;
expr: ValueExpr & { loc?: LocationRange };
}
export type Param = { type: "param"; value: string, loc?: LocationRange; };
export type Param = { type: "param"; value: string; loc?: LocationRange };
export type Value = { type: string; value: any, loc?: LocationRange; };
export type Value = { type: string; value: any; loc?: LocationRange };
export type ExpressionValue = ColumnRef | Param | Function | Case | AggrFunc | Value | Cast | Interval;
export type ExpressionValue =
| ColumnRef
| Param
| Function
| Case
| AggrFunc
| Value
| Cast
| Interval;
export type Expr =
| {
type: "binary_expr";
operator: "AND" | "OR";
left: Expr;
right: Expr;
loc?: LocationRange;
}
type: "binary_expr";
operator: "AND" | "OR";
left: Expr;
right: Expr;
loc?: LocationRange;
}
| {
type: "binary_expr";
operator: string;
left: ExpressionValue;
right: ExpressionValue | ExprList;
loc?: LocationRange;
};
type: "binary_expr";
operator: string;
left: ExpressionValue;
right: ExpressionValue | ExprList;
loc?: LocationRange;
};

@@ -246,2 +280,152 @@ export type ExprList = {

type KW_UNSIGNED = "UNSIGNED";
type KW_ZEROFILL = "ZEROFILL";
type Timezone = ["WITHOUT" | "WITH", "TIME", "ZONE"];
type KeywordComment = {
type: "comment";
keyword: "comment";
symbol?: "=";
value: string;
};
type CollateExpr = {
type: "collate";
symbol?: "=";
value: string;
};
type DataType = {
dataType: string;
length?: number;
parentheses?: true;
suffix?: Timezone | (KW_UNSIGNED | KW_ZEROFILL)[];
array?: "one" | "two";
};
type LiteralNotNull = {
type: "not null";
value: "not null";
};
type LiteralNull = { type: "null"; value: null };
type LiteralNumeric = number | { type: "bigint"; value: string };
type ColumnConstraint = {
default_val: {
type: "default";
value: any;
};
nullable: LiteralNotNull | LiteralNull;
};
type ColumnDefinitionOptList = {
nullable?: ColumnConstraint["nullable"];
default_val?: ColumnConstraint["default_val"];
auto_increment?: "auto_increment";
unique?: "unique" | "unique key";
primary?: "key" | "primary key";
comment?: KeywordComment;
collate?: { collate: CollateExpr };
column_format?: { column_format: any };
storage?: { storage: any };
reference_definition?: { reference_definition: any };
character_set?: { type: "CHARACTER SET"; value: string; symbol?: "=" };
};
type CreateColumnDefinition = {
column: ColumnRef;
definition: DataType;
resource: "column";
} & ColumnDefinitionOptList;
type IndexType = {
keyword: "using";
type: "btree" | "hash" | "gist" | "gin";
};
type IndexOption = {
type: "key_block_size";
symbol?: "=";
expr: LiteralNumeric;
};
type CreateIndexDefinition = {
index?: string;
definition: ColumnRef[];
keyword: "index" | "key";
index_type?: IndexType;
resource: "index";
index_options?: IndexOption[];
};
type CreateFulltextSpatialIndexDefinition = {
index?: string;
definition: ColumnRef[];
keyword?:
| "fulltext"
| "spatial"
| "fulltext key"
| "spatial key"
| "fulltext index"
| "spatial index";
index_options?: IndexOption[];
resource: "index";
};
type ConstraintName = { keyword: "constraint"; constraint: string };
type CreateConstraintPrimary = {
constraint?: ConstraintName["constraint"];
definition: ColumnRef[];
constraint_type: "primary key";
keyword?: ConstraintName["keyword"];
index_type?: IndexType;
resource: "constraint";
index_options?: IndexOption[];
};
type CreateConstraintUnique = {
constraint?: ConstraintName["constraint"];
definition: ColumnRef[];
constraint_type: "unique key" | "unique" | "unique index";
keyword?: ConstraintName["keyword"];
index_type?: IndexType;
index?: string;
resource: "constraint";
index_options?: IndexOption[];
};
type CreateConstraintForeign = {
constraint?: ConstraintName["constraint"];
definition: ColumnRef[];
constraint_type: "FOREIGN KEY";
keyword?: ConstraintName["keyword"];
index?: string;
resource: "constraint";
reference_definition?: any;
};
type CreateConstraintCheck = {
constraint?: ConstraintName["constraint"];
definition: any[];
constraint_type: "check";
keyword?: ConstraintName["keyword"];
resource: "constraint";
};
type CreateConstraintDefinition =
| CreateConstraintPrimary
| CreateConstraintUnique
| CreateConstraintForeign
| CreateConstraintCheck;
type CreateDefinition =
| CreateColumnDefinition
| CreateIndexDefinition
| CreateFulltextSpatialIndexDefinition
| CreateConstraintDefinition;
export interface Create {

@@ -261,3 +445,3 @@ type: "create";

query_expr?: any | null;
create_definitions?: any[] | null;
create_definitions?: CreateDefinition[] | null;
table_options?: any[] | null;

@@ -264,0 +448,0 @@ index_using?: {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc