node-sql-parser
Advanced tools
Comparing version 1.6.2 to 1.6.3
@@ -12,4 +12,8 @@ "use strict"; | ||
var _postgresql = require("../build/postgresql"); | ||
var _sql = _interopRequireDefault(require("./sql")); | ||
var _util = require("./util"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -19,7 +23,8 @@ | ||
mysql: _mysql.parse, | ||
mariadb: _mariadb.parse | ||
mariadb: _mariadb.parse, | ||
postgresql: _postgresql.parse | ||
}; | ||
class Parser { | ||
astify(sql, opt) { | ||
astify(sql, opt = _util.DEFAULT_OPT) { | ||
const astInfo = this.parse(sql, opt); | ||
@@ -29,9 +34,12 @@ return astInfo && astInfo.ast; | ||
sqlify(ast, opt) { | ||
sqlify(ast, opt = _util.DEFAULT_OPT) { | ||
process.env.NODE_SQL_PARSER_OPT = JSON.stringify(opt); | ||
return (0, _sql.default)(ast, opt); | ||
} | ||
parse(sql, { | ||
database = 'mysql' | ||
} = {}) { | ||
parse(sql, opt = _util.DEFAULT_OPT) { | ||
const { | ||
database = 'mysql' | ||
} = opt; | ||
process.env.NODE_SQL_PARSER_OPT = JSON.stringify(opt); | ||
const typeCase = database.toLowerCase(); | ||
@@ -42,3 +50,3 @@ if (parser[typeCase]) return parser[typeCase](sql); | ||
whiteListCheck(sql, whiteList, opt = {}) { | ||
whiteListCheck(sql, whiteList, opt = _util.DEFAULT_OPT) { | ||
if (!whiteList || whiteList.length === 0) return; | ||
@@ -45,0 +53,0 @@ const { |
@@ -19,2 +19,3 @@ "use strict"; | ||
exports.toUpper = toUpper; | ||
exports.DEFAULT_OPT = void 0; | ||
@@ -36,2 +37,7 @@ var _has = _interopRequireDefault(require("has")); | ||
}; | ||
const DEFAULT_OPT = { | ||
database: 'mysql', | ||
type: 'table' | ||
}; | ||
exports.DEFAULT_OPT = DEFAULT_OPT; | ||
@@ -149,6 +155,31 @@ function commonOptionConnector(keyword, action, opt) { | ||
function getParserOpt() { | ||
let opt = DEFAULT_OPT; | ||
try { | ||
opt = JSON.parse(process.env.NODE_SQL_PARSER_OPT); | ||
} catch (parseError) {// ignore error | ||
} | ||
return opt; | ||
} | ||
function identifierToSql(ident, isDual) { | ||
const { | ||
database | ||
} = getParserOpt(); | ||
if (isDual === true) return `'${ident}'`; | ||
if (!ident) return; | ||
return `\`${ident}\``; | ||
switch (database && database.toLowerCase()) { | ||
case 'mysql': | ||
case 'mariadb': | ||
return `\`${ident}\``; | ||
case 'postgresql': | ||
return `"${ident}"`; | ||
default: | ||
return `\`${ident}\``; | ||
} | ||
} | ||
@@ -155,0 +186,0 @@ |
{ | ||
"name": "node-sql-parser", | ||
"version": "1.6.2", | ||
"version": "1.6.3", | ||
"description": "simple node sql parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -51,2 +51,8 @@ # Nodejs SQL Parser | ||
### Supported Database SQL Syntax | ||
- Mysql | ||
- MariaDB | ||
- PostgresQL | ||
### Create AST for SQL statement | ||
@@ -53,0 +59,0 @@ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
1444824
32
51249
222
3