lite-ui-sql-parser
Version:
simple node sql parser
36 lines (32 loc) • 1.16 kB
JavaScript
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports", "./union"], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require("./union"));
} else {
var mod = {
exports: {}
};
factory(mod.exports, global.union);
global.sql = mod.exports;
}
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _union) {
"use strict";
Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = toSQL;
const surportedTypes = ['select', 'delete', 'update', 'insert', 'drop', 'rename', 'truncate', 'call', 'use', 'alter', 'set', 'create', 'lock', 'unlock'];
function checkSupported(expr) {
const ast = expr && expr.ast ? expr.ast : expr;
if (!surportedTypes.includes(ast.type)) throw new Error(`${ast.type} statements not supported at the moment`);
}
function toSQL(ast) {
if (Array.isArray(ast)) {
ast.forEach(checkSupported);
return (0, _union.multipleToSQL)(ast);
}
checkSupported(ast);
return (0, _union.unionToSQL)(ast);
}
});