dbgate-query-splitter
Advanced tools
Comparing version 4.7.4 to 4.8.0
@@ -18,2 +18,3 @@ export interface SplitterOptions { | ||
returnRichInfo: boolean; | ||
splitByLines: boolean; | ||
} | ||
@@ -27,1 +28,2 @@ export declare const defaultSplitterOptions: SplitterOptions; | ||
export declare const noSplitSplitterOptions: SplitterOptions; | ||
export declare const redisSplitterOptions: SplitterOptions; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.noSplitSplitterOptions = exports.mongoSplitterOptions = exports.sqliteSplitterOptions = exports.postgreSplitterOptions = exports.mssqlSplitterOptions = exports.mysqlSplitterOptions = exports.defaultSplitterOptions = void 0; | ||
exports.redisSplitterOptions = exports.noSplitSplitterOptions = exports.mongoSplitterOptions = exports.sqliteSplitterOptions = exports.postgreSplitterOptions = exports.mssqlSplitterOptions = exports.mysqlSplitterOptions = exports.defaultSplitterOptions = void 0; | ||
exports.defaultSplitterOptions = { | ||
@@ -17,2 +17,3 @@ stringsBegins: ["'"], | ||
returnRichInfo: false, | ||
splitByLines: false, | ||
}; | ||
@@ -25,1 +26,2 @@ exports.mysqlSplitterOptions = Object.assign(Object.assign({}, exports.defaultSplitterOptions), { allowCustomDelimiter: true, stringsBegins: ["'", '`'], stringsEnds: { "'": "'", '`': '`' }, stringEscapes: { "'": '\\', '`': '`' } }); | ||
exports.noSplitSplitterOptions = Object.assign(Object.assign({}, exports.defaultSplitterOptions), { noSplit: true }); | ||
exports.redisSplitterOptions = Object.assign(Object.assign({}, exports.defaultSplitterOptions), { splitByLines: true }); |
@@ -198,3 +198,24 @@ "use strict"; | ||
} | ||
function splitByLines(context) { | ||
while (context.position < context.end) { | ||
if (context.source[context.position] == '\n') { | ||
pushQuery(context); | ||
context.commandPart = ''; | ||
movePosition(context, 1); | ||
context.currentCommandStart = context.position; | ||
markStartCommand(context); | ||
} | ||
else { | ||
movePosition(context, 1); | ||
} | ||
} | ||
if (context.end > context.currentCommandStart) { | ||
context.commandPart += context.source.slice(context.currentCommandStart, context.position); | ||
} | ||
} | ||
function splitQueryLine(context) { | ||
if (context.options.splitByLines) { | ||
splitByLines(context); | ||
return; | ||
} | ||
while (context.position < context.end) { | ||
@@ -201,0 +222,0 @@ const token = scanToken(context); |
@@ -71,2 +71,10 @@ "use strict"; | ||
}); | ||
test('redis split by newline', () => { | ||
const output = (0, splitQuery_1.splitQuery)('SET x 1\nSET y 2', options_1.redisSplitterOptions); | ||
expect(output).toEqual(['SET x 1', 'SET y 2']); | ||
}); | ||
test('redis split by newline 2', () => { | ||
const output = (0, splitQuery_1.splitQuery)('SET x 1\n\nSET y 2\n', options_1.redisSplitterOptions); | ||
expect(output).toEqual(['SET x 1', 'SET y 2']); | ||
}); | ||
test('count lines', () => { | ||
@@ -73,0 +81,0 @@ const output = (0, splitQuery_1.splitQuery)('SELECT * FROM `table1`;\nSELECT * FROM `table2`;', Object.assign(Object.assign({}, options_1.mysqlSplitterOptions), { returnRichInfo: true })); |
{ | ||
"version": "4.7.4", | ||
"version": "4.8.0", | ||
"name": "dbgate-query-splitter", | ||
@@ -30,3 +30,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"dbgate-types": "^4.7.4", | ||
"dbgate-types": "^4.8.0", | ||
"@types/jest": "^25.1.4", | ||
@@ -33,0 +33,0 @@ "@types/node": "^13.7.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
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
29872
696