1
- function whereComp ( prop , operator , val ) //operator comparison for where clause
2
- {
1
+ const ejf = require ( 'edit-json-file' ) ;
2
+ let config = ejf ( './.config.json' ) ;
3
+ const uniqid = require ( 'uniqid' ) ;
4
+ const log = require ( 'simple-node-logger' ) . createSimpleFileLogger ( config . get ( "logs.lazlo_log" ) ) ;
5
+
6
+ //operator comparison for where clause
7
+ function whereComp ( prop , operator , val ) {
3
8
let output = [ ] ;
4
9
5
- if ( operator === '=' ) {
10
+ if ( operator === '=' ) {
6
11
cache . forEach ( ( obj ) => {
7
- if ( obj [ prop ] == val ) {
12
+ if ( obj [ prop ] == val ) {
8
13
output . push ( obj ) ;
9
14
}
10
15
} ) ;
11
- }
12
- else if ( operator === '!=' ) {
16
+ } else if ( operator === '!=' ) {
13
17
cache . forEach ( ( obj ) => {
14
- if ( obj [ prop ] != val ) {
18
+ if ( obj [ prop ] != val ) {
15
19
output . push ( obj ) ;
16
20
}
17
21
} ) ;
18
- }
19
- else if ( operator === '>' ) {
22
+ } else if ( operator === '>' ) {
20
23
cache . forEach ( ( obj ) => {
21
- if ( obj [ prop ] > val ) {
24
+ if ( obj [ prop ] > val ) {
22
25
output . push ( obj ) ;
23
26
}
24
27
} ) ;
25
- }
26
- else if ( operator === '<' ) {
28
+ } else if ( operator === '<' ) {
27
29
cache . forEach ( ( obj ) => {
28
- if ( obj [ prop ] < val ) {
30
+ if ( obj [ prop ] < val ) {
29
31
output . push ( obj ) ;
30
32
}
31
33
} ) ;
32
- }
33
- else if ( operator === '>=' ) {
34
+ } else if ( operator === '>=' ) {
34
35
cache . forEach ( ( obj ) => {
35
- if ( obj [ prop ] > val || obj [ prop ] == val ) {
36
+ if ( obj [ prop ] > val || obj [ prop ] == val ) {
36
37
output . push ( obj ) ;
37
38
}
38
39
} ) ;
39
- }
40
- else if ( operator === '<=' ) {
40
+ } else if ( operator === '<=' ) {
41
41
cache . forEach ( ( obj ) => {
42
- if ( obj [ prop ] < val || obj [ prop ] == val ) {
42
+ if ( obj [ prop ] < val || obj [ prop ] == val ) {
43
43
output . push ( obj ) ;
44
44
}
45
45
} ) ;
46
+ } else {
47
+ output = null ;
46
48
}
47
49
return output ;
48
50
}
49
- module . exports . whereComp = whereComp ;
51
+
52
+ module . exports . whereComp = whereComp ;
53
+
54
+ //id generator
55
+ function idgen ( ) {
56
+ let prefix = new Date ( ) . toISOString ( ) . substr ( 0 , 10 ) ;
57
+ return id = uniqid ( `${ prefix } @` ) ;
58
+ }
59
+
60
+ module . exports . idgen = idgen ;
61
+
62
+ //log generators
63
+ function docEntryLog ( count , docname , op ) {
64
+ if ( op === true ) {
65
+ log . info ( `DE : ${ count } entries added to ${ docname } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
66
+ } else {
67
+ log . warn ( `DR : ${ count } entries removed from ${ docname } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
68
+ }
69
+ }
70
+
71
+ module . exports . docEntryLog = docEntryLog ;
72
+
73
+ function docCreationLog ( docname , db ) {
74
+ log . info ( `DC : ${ docname } created in ${ db } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
75
+ }
76
+
77
+ module . exports . docCreationLog = docCreationLog ;
78
+
79
+ function docDeletionLog ( docname , db ) {
80
+ log . warn ( `DD : ${ docname } deleted from ${ db } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
81
+ }
82
+
83
+ module . exports . docDeletionLog = docDeletionLog ;
84
+
85
+ function dbLog ( op ) {
86
+ if ( op === true ) {
87
+ log . info ( `DBC : ${ db } created in ${ config . get ( "db_src" ) } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
88
+ } else {
89
+ log . warn ( `DBD : ${ db } deleted from ${ config . get ( "db_src" ) } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
90
+ }
91
+ }
92
+
93
+ module . exports . dbLog = dbLog ;
94
+
95
+ function docUpdateLog ( id , docname ) {
96
+ log . info ( `DU : Entry(id : ${ id } ) updated in ${ docname } on ` , new Date ( ) . toISOString ( ) . replace ( 'T' , '@' ) . substr ( 0 , 16 ) ) ;
97
+ }
98
+
99
+ module . exports . docUpdateLog = docUpdateLog ;
0 commit comments