node-sql-parser
Advanced tools
Comparing version 1.8.3 to 1.8.4
(function (global, factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["exports", "./index-definition", "./column", "./constrain", "./tables", "./union", "./util"], factory); | ||
define(["exports", "./expr", "./index-definition", "./column", "./constrain", "./func", "./tables", "./union", "./util"], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports, require("./index-definition"), require("./column"), require("./constrain"), require("./tables"), require("./union"), require("./util")); | ||
factory(exports, require("./expr"), require("./index-definition"), require("./column"), require("./constrain"), require("./func"), require("./tables"), require("./union"), require("./util")); | ||
} else { | ||
@@ -10,6 +10,6 @@ var mod = { | ||
}; | ||
factory(mod.exports, global.indexDefinition, global.column, global.constrain, global.tables, global.union, global.util); | ||
factory(mod.exports, global.expr, global.indexDefinition, global.column, global.constrain, global.func, global.tables, global.union, global.util); | ||
global.create = mod.exports; | ||
} | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _indexDefinition, _column, _constrain, _tables, _union, _util) { | ||
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _indexDefinition, _column, _constrain, _func, _tables, _union, _util) { | ||
"use strict"; | ||
@@ -43,3 +43,3 @@ | ||
function createToSQL(stmt) { | ||
function createTableToSQL(stmt) { | ||
const { | ||
@@ -82,2 +82,44 @@ type, | ||
} | ||
function createTriggerToSQL(stmt) { | ||
const { | ||
constraint, | ||
constraint_kw: constraintKw, | ||
deferrable, | ||
events, | ||
execute, | ||
for_each: forEach, | ||
from, | ||
location, | ||
keyword, | ||
type, | ||
table, | ||
when | ||
} = stmt; | ||
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(constraintKw), (0, _util.toUpper)(keyword), (0, _util.identifierToSql)(constraint), (0, _util.toUpper)(location)]; | ||
const event = (0, _util.triggerEventToSQL)(events); | ||
sql.push(event, 'ON', (0, _tables.tableToSQL)(table)); | ||
if (from) sql.push('FROM', (0, _tables.tableToSQL)(from)); | ||
sql.push(...(0, _util.commonKeywordArgsToSQL)(deferrable), ...(0, _util.commonKeywordArgsToSQL)(forEach)); | ||
if (when) sql.push((0, _util.toUpper)(when.type), (0, _expr.exprToSQL)(when.cond)); | ||
sql.push((0, _util.toUpper)(execute.keyword), (0, _func.funcToSQL)(execute.expr)); | ||
return sql.filter(_util.hasVal).join(' '); | ||
} | ||
function createToSQL(stmt) { | ||
const { | ||
keyword | ||
} = stmt; | ||
switch (keyword.toLowerCase()) { | ||
case 'table': | ||
return createTableToSQL(stmt); | ||
case 'trigger': | ||
return createTriggerToSQL(stmt); | ||
default: | ||
throw new Error(`unknow create resource ${keyword}`); | ||
} | ||
} | ||
}); |
@@ -19,2 +19,3 @@ (function (global, factory) { | ||
}); | ||
_exports.commonKeywordArgsToSQL = commonKeywordArgsToSQL; | ||
_exports.commonOptionConnector = commonOptionConnector; | ||
@@ -36,2 +37,3 @@ _exports.connector = connector; | ||
_exports.topToSQL = topToSQL; | ||
_exports.triggerEventToSQL = triggerEventToSQL; | ||
_exports.DEFAULT_OPT = void 0; | ||
@@ -313,2 +315,22 @@ const escapeMap = { | ||
function triggerEventToSQL(events) { | ||
return events.map(event => { | ||
const { | ||
keyword: kw, | ||
args | ||
} = event; | ||
const result = [toUpper(kw)]; | ||
if (args) { | ||
const { | ||
keyword: kwArgs, | ||
columns | ||
} = args; | ||
result.push(toUpper(kwArgs), columns.map(columnRefToSQL).join(', ')); | ||
} | ||
return result.join(' '); | ||
}).join(' OR '); | ||
} | ||
function returningToSQL(returning) { | ||
@@ -321,2 +343,7 @@ if (!returning) return ''; | ||
} | ||
function commonKeywordArgsToSQL(kwArgs) { | ||
if (!kwArgs) return []; | ||
return [toUpper(kwArgs.keyword), toUpper(kwArgs.args)]; | ||
} | ||
}); |
{ | ||
"name": "node-sql-parser", | ||
"version": "1.8.3", | ||
"version": "1.8.4", | ||
"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 too big to display
3482209
95880