File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed
Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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+
243255test ( 'shash delimiter' , ( ) => {
244256 const input = 'SELECT 1\n/\nSELECT 2\n' ;
245257 const output = splitQuery ( input , oracleSplitterOptions ) ;
You can’t perform that action at this time.
0 commit comments