Skip to content

Commit 3c07fa1

Browse files
author
SPRINX0\prochazka
committed
split by empty lines
1 parent 7a484b1 commit 3c07fa1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface SplitterOptions {
2525

2626
returnRichInfo: boolean;
2727
splitByLines: boolean;
28+
splitByEmptyLine: boolean;
2829

2930
copyFromStdin: boolean;
3031

@@ -51,6 +52,7 @@ export const defaultSplitterOptions: SplitterOptions = {
5152

5253
returnRichInfo: false,
5354
splitByLines: false,
55+
splitByEmptyLine: false,
5456
preventSingleLineSplit: false,
5557
adaptiveGoSplit: false,
5658
ignoreComments: false,

src/splitQuery.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ export function splitQueryLine(context: SplitLineContext) {
534534
context.wasDataOnLine = true;
535535
break;
536536
case 'eoln':
537+
if (!context.wasDataOnLine && context.options.splitByEmptyLine) {
538+
pushQuery(context);
539+
context.commandPart = '';
540+
movePosition(context, token.length, false);
541+
context.currentCommandStart = context.position;
542+
context.wasDataOnLine = false;
543+
markStartCommand(context);
544+
break;
545+
}
537546
movePosition(context, token.length, true);
538547
context.wasDataOnLine = false;
539548
break;

src/splitter.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ test('count lines with flush', () => {
240240
);
241241
});
242242

243+
test('empty line delimiter', () => {
244+
const input = 'SELECT 1\n\n \nSELECT 2\n';
245+
const output = splitQuery(input, { ...mysqlSplitterOptions, splitByEmptyLine: true });
246+
expect(output).toEqual(['SELECT 1', 'SELECT 2']);
247+
});
248+
249+
test('empty line delimiter - 2 lines', () => {
250+
const input = 'SELECT 1\n\n \nSELECT 2\nSELECT 3\n';
251+
const output = splitQuery(input, { ...mysqlSplitterOptions, splitByEmptyLine: true });
252+
expect(output).toEqual(['SELECT 1', 'SELECT 2\nSELECT 3']);
253+
});
254+
243255
test('shash delimiter', () => {
244256
const input = 'SELECT 1\n/\nSELECT 2\n';
245257
const output = splitQuery(input, oracleSplitterOptions);

0 commit comments

Comments
 (0)