@@ -109,12 +109,15 @@ var Sql = function () {
109
109
var toReplace = matchFromExec [ 1 ] ;
110
110
while ( fromMatch = matchVariable . exec ( toReplace ) ) {
111
111
if ( typeof fromMatch !== 'undefined' && fromMatch !== null && typeof fromMatch [ 1 ] !== 'undefined' && fromMatch [ 1 ] !== null ) {
112
- var value = Sql . deep_value_array ( jsonPage , fromMatch [ 1 ] ) ;
113
- if ( typeof value !== 'undefined' && value !== null ) {
114
- toReplace = toReplace . replace ( '{{' + fromMatch [ 1 ] + '}}' , value ) ;
115
- } else {
116
- toReplace = toReplace . replace ( '{{' + fromMatch [ 1 ] + '}}' , '' ) ;
117
- }
112
+
113
+ try {
114
+ var value = eval ( 'jsonPage.' + fromMatch [ 1 ] ) ;
115
+ if ( typeof value !== 'undefined' && value !== null ) {
116
+ toReplace = toReplace . replace ( '{{' + fromMatch [ 1 ] + '}}' , value ) ;
117
+ } else {
118
+ toReplace = toReplace . replace ( '{{' + fromMatch [ 1 ] + '}}' , '' ) ;
119
+ }
120
+ } catch ( e ) { }
118
121
}
119
122
}
120
123
@@ -358,10 +361,12 @@ var Sql = function () {
358
361
359
362
var fromDirectory = Sql . getFromDirectory ( from , pathFromClause ) ;
360
363
364
+ var dateStart = new Date ( ) ;
365
+
361
366
var list = _ . Manager . instance . getList ( ) ;
362
- var files_array = list [ 0 ] . files . filter ( function ( element , index , arr ) {
363
- if ( typeof element . published !== 'undefined' && element . published !== null ) {
364
- if ( element . published . path . indexOf ( fromDirectory ) > - 1 ) {
367
+ var files_array = list . filter ( function ( element , index , arr ) {
368
+ if ( element . published ) {
369
+ if ( element . path . indexOf ( fromDirectory ) > - 1 ) {
365
370
return true ;
366
371
}
367
372
}
@@ -429,59 +434,6 @@ var Sql = function () {
429
434
430
435
return 'other' ;
431
436
}
432
- } , {
433
- key : 'deep_value' ,
434
- value : function deep_value ( obj , pathDeep ) {
435
-
436
- if ( pathDeep . indexOf ( '.' ) === - 1 ) {
437
- return typeof obj [ pathDeep ] !== 'undefined' && obj [ pathDeep ] !== null ? obj [ pathDeep ] : null ;
438
- }
439
-
440
- var pathSplit = pathDeep . split ( '.' ) ;
441
- var res = JSON . parse ( JSON . stringify ( obj ) ) ;
442
- for ( var i = 0 ; i < pathSplit . length ; i ++ ) {
443
- if ( typeof res [ pathSplit [ i ] ] !== 'undefined' && res [ pathSplit [ i ] ] !== null ) {
444
- res = res [ pathSplit [ i ] ] ;
445
- } else {
446
- return null ;
447
- }
448
- }
449
-
450
- return res ;
451
- }
452
- } , {
453
- key : 'deep_value_array' ,
454
- value : function deep_value_array ( obj , pathDeep ) {
455
-
456
- if ( pathDeep . indexOf ( '.' ) === - 1 ) {
457
- return typeof obj [ pathDeep ] !== 'undefined' && obj [ pathDeep ] !== null ? obj [ pathDeep ] : null ;
458
- }
459
-
460
- var pathSplit = pathDeep . split ( '.' ) ;
461
- var res = JSON . parse ( JSON . stringify ( obj ) ) ;
462
-
463
- while ( pathSplit . length > 0 ) {
464
-
465
- if ( typeof res [ pathSplit [ 0 ] ] !== 'undefined' && res [ pathSplit [ 0 ] ] !== null ) {
466
- if ( _typeof ( res [ pathSplit [ 0 ] ] ) === 'object' && Object . prototype . toString . call ( res [ pathSplit [ 0 ] ] ) === '[object Array]' ) {
467
- var resArray = [ ] ;
468
-
469
- Array . prototype . forEach . call ( res [ pathSplit [ 0 ] ] , function ( item ) {
470
- resArray . push ( Sql . deep_value_array ( item , pathSplit . join ( '.' ) . replace ( pathSplit [ 0 ] + '.' , '' ) ) ) ;
471
- } ) ;
472
- res = resArray ;
473
- pathSplit . shift ( ) ;
474
- } else {
475
- res = res [ pathSplit [ 0 ] ] ;
476
- }
477
- } else {
478
- return null ;
479
- }
480
- pathSplit . shift ( ) ;
481
- }
482
-
483
- return res ;
484
- }
485
437
} , {
486
438
key : 'executeWhereClause' ,
487
439
value : function executeWhereClause ( files , wheres , maxLimit , columns , jsonPage ) {
@@ -497,26 +449,28 @@ var Sql = function () {
497
449
var file = _step . value ;
498
450
499
451
if ( limit < maxLimit || maxLimit === - 1 ) {
500
- var doc = Sql . executeWhereClauseToFile ( file . published , wheres , jsonPage ) ;
452
+ if ( file . published === true ) {
453
+ var doc = Sql . executeWhereClauseOnDocument ( file , wheres , jsonPage ) ;
501
454
502
- if ( doc ) {
503
- var json = JSON . parse ( JSON . stringify ( doc ) ) ;
504
- var jsonValues = { } ;
455
+ if ( doc ) {
456
+ var json = JSON . parse ( JSON . stringify ( doc ) ) ;
457
+ var jsonValues = { } ;
505
458
506
- if ( typeof columns !== 'undefined' && columns !== null && columns . length > 0 && columns [ 0 ] !== '*' ) {
459
+ if ( typeof columns !== 'undefined' && columns !== null && columns . length > 0 && columns [ 0 ] !== '*' ) {
507
460
508
- Array . prototype . forEach . call ( columns , function ( column ) {
509
- if ( typeof json [ column ] !== 'undefined' && json [ column ] !== null ) {
510
- jsonValues [ column ] = json [ column ] ;
511
- }
512
- } ) ;
513
- jsonValues [ _ . config . meta . name ] = json [ _ . config . meta . name ] ;
514
- } else {
515
- jsonValues = json ;
516
- }
461
+ Array . prototype . forEach . call ( columns , function ( column ) {
462
+ if ( typeof json [ column ] !== 'undefined' && json [ column ] !== null ) {
463
+ jsonValues [ column ] = json [ column ] ;
464
+ }
465
+ } ) ;
466
+ jsonValues [ _ . config . meta . name ] = json [ _ . config . meta . name ] ;
467
+ } else {
468
+ jsonValues = json ;
469
+ }
517
470
518
- res . push ( jsonValues ) ;
519
- limit ++ ;
471
+ res . push ( jsonValues ) ;
472
+ limit ++ ;
473
+ }
520
474
}
521
475
} else {
522
476
break ;
@@ -683,37 +637,41 @@ var Sql = function () {
683
637
return shouldAdd ;
684
638
}
685
639
} , {
686
- key : 'executeWhereClauseToFile' ,
687
- value : function executeWhereClauseToFile ( file , wheres , jsonPage ) {
688
- var json = file ;
689
- // if (fileUtils.isFile(file.path)) {
690
- // json = fse.readJsonSync(file.path)
691
- // }
692
- //
693
- var shouldAdd = json ;
640
+ key : 'executeWhereClauseOnDocument' ,
641
+ value : function executeWhereClauseOnDocument ( jsonDoc , wheres , jsonOriginalDoc ) {
642
+ var shouldAdd = jsonDoc ;
694
643
695
644
if ( typeof wheres !== 'undefined' && wheres !== null ) {
696
645
( function ( ) {
697
646
var meta = _ . config . meta . name ;
698
- if ( typeof json [ meta ] !== 'undefined' && json [ meta ] !== null ) {
647
+ if ( typeof jsonDoc [ meta ] !== 'undefined' && jsonDoc [ meta ] !== null ) {
699
648
Array . prototype . forEach . call ( wheres , function ( where ) {
700
649
var value ;
701
650
var compare ;
702
651
703
652
if ( where . left === 'template' || where . left === 'abe_meta.template' ) {
704
- value = _ . FileParser . getTemplate ( json [ meta ] . template ) ;
653
+ value = _ . FileParser . getTemplate ( jsonDoc [ meta ] . template ) ;
705
654
} else {
706
- value = Sql . deep_value_array ( json , where . left ) ;
655
+ try {
656
+ value = eval ( 'jsonDoc.' + where . left ) ;
657
+ } catch ( e ) {
658
+ // console.log('e', e)
659
+ }
707
660
}
708
661
compare = where . right ;
709
662
710
663
var matchVariable = / ^ { { ( .* ) } } $ / . exec ( compare ) ;
711
664
if ( typeof matchVariable !== 'undefined' && matchVariable !== null && matchVariable . length > 0 ) {
712
- var shouldCompare = Sql . deep_value_array ( jsonPage , matchVariable [ 1 ] ) ;
713
- if ( typeof shouldCompare !== 'undefined' && shouldCompare !== null ) {
714
- compare = shouldCompare ;
715
- } else {
665
+ try {
666
+ var shouldCompare = eval ( 'jsonOriginalDoc.' + matchVariable [ 1 ] ) ;
667
+ if ( typeof shouldCompare !== 'undefined' && shouldCompare !== null ) {
668
+ compare = shouldCompare ;
669
+ } else {
670
+ shouldAdd = false ;
671
+ }
672
+ } catch ( e ) {
716
673
shouldAdd = false ;
674
+ // console.log('e', e)
717
675
}
718
676
}
719
677
0 commit comments