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 1.6.2 to 1.6.3

build/postgresql.js

22

lib/parser.js

@@ -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 @@

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