1
1
/**
2
- * mysql-import - v5.0.26
2
+ * mysql-import - v5.1.1
3
3
* Import .sql into a MySQL database with Node.
4
4
* @author Rob Parham
5
5
* @website https://github.com/pamblam/mysql-import#readme
@@ -16,7 +16,7 @@ const stream = require('stream');
16
16
17
17
/**
18
18
* mysql-import - Importer class
19
- * @version 5.0.26
19
+ * @version 5.1.1
20
20
* https://github.com/Pamblam/mysql-import
21
21
*/
22
22
@@ -133,19 +133,26 @@ class Importer{
133
133
this . _current_file_no = 0 ;
134
134
135
135
var error = null ;
136
- await slowLoop ( files , ( file , index , next ) => {
137
- this . _current_file_no ++ ;
138
- if ( error ) {
139
- next ( ) ;
140
- return ;
141
- }
142
- this . _importSingleFile ( file ) . then ( ( ) => {
143
- next ( ) ;
144
- } ) . catch ( err => {
145
- error = err ;
146
- next ( ) ;
136
+
137
+
138
+
139
+ for ( let i = 0 ; i < files . length ; i ++ ) {
140
+ let file = files [ i ] ;
141
+ await new Promise ( next => {
142
+ this . _current_file_no ++ ;
143
+ if ( error ) {
144
+ next ( ) ;
145
+ return ;
146
+ }
147
+ this . _importSingleFile ( file ) . then ( ( ) => {
148
+ next ( ) ;
149
+ } ) . catch ( err => {
150
+ error = err ;
151
+ next ( ) ;
152
+ } ) ;
147
153
} ) ;
148
- } ) ;
154
+ }
155
+
149
156
if ( error ) throw error ;
150
157
await this . disconnect ( ) ;
151
158
resolve ( ) ;
@@ -325,37 +332,42 @@ class Importer{
325
332
var full_paths = [ ] ;
326
333
var error = null ;
327
334
paths = [ ] . concat . apply ( [ ] , paths ) ; // flatten array of paths
328
- await slowLoop ( paths , async ( filepath , index , next ) => {
329
- if ( error ) {
330
- next ( ) ;
331
- return ;
332
- }
333
- try {
334
- await this . _fileExists ( filepath ) ;
335
- var stat = await this . _statFile ( filepath ) ;
336
- if ( stat . isFile ( ) ) {
337
- if ( filepath . toLowerCase ( ) . substring ( filepath . length - 4 ) === '.sql' ) {
338
- full_paths . push ( {
339
- file : path . resolve ( filepath ) ,
340
- size : stat . size
341
- } ) ;
342
- }
343
- next ( ) ;
344
- } else if ( stat . isDirectory ( ) ) {
345
- var more_paths = await this . _readDir ( filepath ) ;
346
- more_paths = more_paths . map ( p => path . join ( filepath , p ) ) ;
347
- var sql_files = await this . _getSQLFilePaths ( ...more_paths ) ;
348
- full_paths . push ( ...sql_files ) ;
335
+
336
+ for ( let i = 0 ; i < paths . length ; i ++ ) {
337
+ let filepath = paths [ i ] ;
338
+ await new Promise ( async next => {
339
+ if ( error ) {
349
340
next ( ) ;
350
- } else {
351
- /* istanbul ignore next */
341
+ return ;
342
+ }
343
+ try {
344
+ await this . _fileExists ( filepath ) ;
345
+ var stat = await this . _statFile ( filepath ) ;
346
+ if ( stat . isFile ( ) ) {
347
+ if ( filepath . toLowerCase ( ) . substring ( filepath . length - 4 ) === '.sql' ) {
348
+ full_paths . push ( {
349
+ file : path . resolve ( filepath ) ,
350
+ size : stat . size
351
+ } ) ;
352
+ }
353
+ next ( ) ;
354
+ } else if ( stat . isDirectory ( ) ) {
355
+ var more_paths = await this . _readDir ( filepath ) ;
356
+ more_paths = more_paths . map ( p => path . join ( filepath , p ) ) ;
357
+ var sql_files = await this . _getSQLFilePaths ( ...more_paths ) ;
358
+ full_paths . push ( ...sql_files ) ;
359
+ next ( ) ;
360
+ } else {
361
+ /* istanbul ignore next */
362
+ next ( ) ;
363
+ }
364
+ } catch ( err ) {
365
+ error = err ;
352
366
next ( ) ;
353
367
}
354
- } catch ( err ) {
355
- error = err ;
356
- next ( ) ;
357
- }
358
- } ) ;
368
+ } ) ;
369
+ }
370
+
359
371
if ( error ) {
360
372
reject ( error ) ;
361
373
} else {
@@ -369,34 +381,10 @@ class Importer{
369
381
/**
370
382
* Build version number
371
383
*/
372
- Importer . version = '5.0.26 ' ;
384
+ Importer . version = '5.1.1 ' ;
373
385
374
386
module . exports = Importer ;
375
387
376
- /**
377
- * Execute the loopBody function once for each item in the items array,
378
- * waiting for the done function (which is passed into the loopBody function)
379
- * to be called before proceeding to the next item in the array.
380
- * @param {Array } items - The array of items to iterate through
381
- * @param {Function } loopBody - A function to execute on each item in the array.
382
- * This function is passed 3 arguments -
383
- * 1. The item in the current iteration,
384
- * 2. The index of the item in the array,
385
- * 3. A function to be called when the iteration may continue.
386
- * @returns {Promise } - A promise that is resolved when all the items in the
387
- * in the array have been iterated through.
388
- */
389
- function slowLoop ( items , loopBody ) {
390
- return new Promise ( f => {
391
- /* istanbul ignore next */
392
- if ( ! items . length ) return f ( ) ;
393
- let done = arguments [ 2 ] || f ;
394
- let idx = arguments [ 3 ] || 0 ;
395
- let cb = items [ idx + 1 ] ? ( ) => slowLoop ( items , loopBody , done , idx + 1 ) : done ;
396
- loopBody ( items [ idx ] , idx , cb ) ;
397
- } ) ;
398
- }
399
-
400
388
401
389
class queryParser extends stream . Writable {
402
390
0 commit comments