Skip to content

Commit d3fd7f9

Browse files
author
zaygo
committed
added all doc & slice&dice features, added log feature
1 parent 57e19a0 commit d3fd7f9

File tree

8 files changed

+470
-47
lines changed

8 files changed

+470
-47
lines changed

.config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"db_src": "C://Users/arjun/Documents",
33
"logs": {
4-
"lazlo_log": "./logs/lazlo.log",
5-
"custom_log": null
4+
"lazlo_log": "./logs/lazlo.log"
65
}
76
}

common-functions.js

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,99 @@
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) {
38
let output = [];
49

5-
if(operator === '=') {
10+
if (operator === '=') {
611
cache.forEach((obj) => {
7-
if(obj[prop] == val) {
12+
if (obj[prop] == val) {
813
output.push(obj);
914
}
1015
});
11-
}
12-
else if(operator === '!=') {
16+
} else if (operator === '!=') {
1317
cache.forEach((obj) => {
14-
if(obj[prop] != val) {
18+
if (obj[prop] != val) {
1519
output.push(obj);
1620
}
1721
});
18-
}
19-
else if(operator === '>') {
22+
} else if (operator === '>') {
2023
cache.forEach((obj) => {
21-
if(obj[prop] > val) {
24+
if (obj[prop] > val) {
2225
output.push(obj);
2326
}
2427
});
25-
}
26-
else if(operator === '<') {
28+
} else if (operator === '<') {
2729
cache.forEach((obj) => {
28-
if(obj[prop] < val) {
30+
if (obj[prop] < val) {
2931
output.push(obj);
3032
}
3133
});
32-
}
33-
else if(operator === '>=') {
34+
} else if (operator === '>=') {
3435
cache.forEach((obj) => {
35-
if(obj[prop] > val || obj[prop] == val) {
36+
if (obj[prop] > val || obj[prop] == val) {
3637
output.push(obj);
3738
}
3839
});
39-
}
40-
else if(operator === '<=') {
40+
} else if (operator === '<=') {
4141
cache.forEach((obj) => {
42-
if(obj[prop] < val || obj[prop] == val) {
42+
if (obj[prop] < val || obj[prop] == val) {
4343
output.push(obj);
4444
}
4545
});
46+
} else {
47+
output = null;
4648
}
4749
return output;
4850
}
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

Comments
 (0)