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

dbgate-query-splitter

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dbgate-query-splitter - npm Package Compare versions

Comparing version 4.9.0 to 4.9.1

2

lib/options.d.ts

@@ -17,2 +17,4 @@ export interface SplitterOptions {

javaScriptComments: boolean;
preventSingleLineSplit: boolean;
adaptiveGoSplit: boolean;
returnRichInfo: boolean;

@@ -19,0 +21,0 @@ splitByLines: boolean;

@@ -18,2 +18,4 @@ "use strict";

splitByLines: false,
preventSingleLineSplit: false,
adaptiveGoSplit: false,
};

@@ -20,0 +22,0 @@ exports.mysqlSplitterOptions = Object.assign(Object.assign({}, exports.defaultSplitterOptions), { allowCustomDelimiter: true, stringsBegins: ["'", '`'], stringsEnds: { "'": "'", '`': '`' }, stringEscapes: { "'": '\\', '`': '`' } });

@@ -137,3 +137,3 @@ "use strict";

}
if (context.options.allowGoDelimiter && !context.wasDataOnLine) {
if ((context.options.allowGoDelimiter || context.options.adaptiveGoSplit) && !context.wasDataOnLine) {
const m = s.slice(pos).match(/^GO[\t\r ]*(\n|$)/i);

@@ -147,2 +147,11 @@ if (m) {

}
if (context.options.adaptiveGoSplit) {
const m = s.slice(pos).match(/^CREATE\s*(PROCEDURE|FUNCTION|TRIGGER)/i);
if (m) {
return {
type: 'create_routine',
length: m[0].length - 1,
};
}
}
const dollarString = scanDollarQuotedString(context);

@@ -153,2 +162,31 @@ if (dollarString)

}
function containsDataAfterDelimiterOnLine(context, delimiter) {
var _a;
const cloned = {
options: context.options,
source: context.source,
position: context.position,
currentDelimiter: context.currentDelimiter,
end: context.end,
wasDataOnLine: context.wasDataOnLine,
};
cloned.position += delimiter.length;
while (cloned.position < cloned.end) {
const token = scanToken(cloned);
if (!token) {
cloned.position += 1;
continue;
}
switch (token.type) {
case 'data':
return true;
case 'eoln':
return false;
case 'comment':
if ((_a = token.value) === null || _a === void 0 ? void 0 : _a.includes('\n'))
return true;
}
cloned.position += token.length;
}
}
function pushQuery(context) {

@@ -264,4 +302,18 @@ const sql = (context.commandPart || '') + context.source.slice(context.currentCommandStart, context.position);

markStartCommand(context);
if (context.options.adaptiveGoSplit) {
context.currentDelimiter = SEMICOLON;
}
break;
case 'create_routine':
movePosition(context, token.length);
if (context.options.adaptiveGoSplit) {
context.currentDelimiter = null;
}
break;
case 'delimiter':
if (context.options.preventSingleLineSplit && containsDataAfterDelimiterOnLine(context, token)) {
movePosition(context, token.length);
context.wasDataOnLine = true;
break;
}
pushQuery(context);

@@ -281,2 +333,4 @@ context.commandPart = '';

function getInitialDelimiter(options) {
if (options === null || options === void 0 ? void 0 : options.adaptiveGoSplit)
return SEMICOLON;
return (options === null || options === void 0 ? void 0 : options.allowSemicolon) === false ? null : SEMICOLON;

@@ -283,0 +337,0 @@ }

@@ -36,2 +36,10 @@ "use strict";

});
test('prevent single line split - mysql', () => {
const output = (0, splitQuery_1.splitQuery)('SELECT * FROM `table1`;SELECT * FROM `table2`;\nSELECT * FROM `table3`', Object.assign(Object.assign({}, options_1.mysqlSplitterOptions), { preventSingleLineSplit: true }));
expect(output).toEqual(['SELECT * FROM `table1`;SELECT * FROM `table2`', 'SELECT * FROM `table3`']);
});
test('adaptive go split -mssql', () => {
const output = (0, splitQuery_1.splitQuery)('SELECT 1;CREATE PROCEDURE p1 AS BEGIN SELECT 2;SELECT 3;END\nGO\nSELECT 4;SELECT 5', Object.assign(Object.assign({}, options_1.mssqlSplitterOptions), { adaptiveGoSplit: true }));
expect(output).toEqual(['SELECT 1', 'CREATE PROCEDURE p1 AS BEGIN SELECT 2;SELECT 3;END', 'SELECT 4', 'SELECT 5']);
});
test('delimiter test', () => {

@@ -38,0 +46,0 @@ const input = 'SELECT 1;\n DELIMITER $$\n SELECT 2; SELECT 3; \n DELIMITER ;';

2

package.json
{
"version": "4.9.0",
"version": "4.9.1",
"name": "dbgate-query-splitter",

@@ -4,0 +4,0 @@ "main": "lib/index.js",

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