applay-utils 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/mdb.js +24 -16
- package/utils/query.js +8 -0
package/package.json
CHANGED
package/utils/mdb.js
CHANGED
|
@@ -7,14 +7,16 @@ var MDB = {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
var connect= (alias,url,callback)=>{
|
|
10
|
+
console.log('Conectando..',alias,' - url:',url);
|
|
10
11
|
if(MDB.status[alias]){return callback(MDB.clients[alias]);}
|
|
11
12
|
MongoBase.MongoClient.connect(url,{useUnifiedTopology: true}, (err, client)=>{
|
|
12
13
|
if(err){return console.log('ERRO MDB -- TRACKING -- ',err);}
|
|
13
14
|
MDB.status[alias]=true;
|
|
14
15
|
MDB.clients[alias]=client;
|
|
15
|
-
process.on('SIGTERM', internalStop());
|
|
16
|
-
process.on('SIGINT' , internalStop());
|
|
17
|
-
process.on('uncaughtException', internalStop());
|
|
16
|
+
process.on('SIGTERM', internalStop(alias,true,'SIGTERM'));
|
|
17
|
+
process.on('SIGINT' , internalStop(alias,true,'SIGINT'));
|
|
18
|
+
process.on('uncaughtException', internalStop(alias,true,'uncaughtException'));
|
|
19
|
+
console.log('Conectado com ',alias);
|
|
18
20
|
callback(client)
|
|
19
21
|
});
|
|
20
22
|
}
|
|
@@ -22,27 +24,34 @@ var connect= (alias,url,callback)=>{
|
|
|
22
24
|
var connectAsync = (alias, url) => new Promise(resolve => connect(alias,url,(client)=>resolve(client)));
|
|
23
25
|
|
|
24
26
|
var internalStop = (alias,finish)=>{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
MDB.
|
|
27
|
+
return (code)=>{
|
|
28
|
+
console.log('Desconnecting...');
|
|
29
|
+
if(!MDB.status[alias]){console.log('Mongodb OFF');return}
|
|
30
|
+
MDB.status[alias] = false;
|
|
31
|
+
MDB.clients[alias].close();
|
|
32
|
+
if(finish&&MDB.stopCustom){
|
|
33
|
+
MDB.stop(alias,()=>{
|
|
34
|
+
console.log('Mongodb',alias,'OFF');
|
|
35
|
+
process.exit();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if(finish&&!MDB.stopCustom){
|
|
39
|
+
console.log('Mongodb',alias,'OFF');
|
|
29
40
|
process.exit();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
}
|
|
42
|
+
if(!finish){
|
|
43
|
+
console.log('Mongodb',alias,'OFF');
|
|
44
|
+
}
|
|
34
45
|
}
|
|
46
|
+
|
|
35
47
|
}
|
|
48
|
+
|
|
36
49
|
|
|
37
50
|
var stopCustom = (customCallback)=>{
|
|
38
51
|
MDB.stopCustom=true;
|
|
39
52
|
MDB.stop = customCallback;
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
var stop = (alias)=>{
|
|
43
|
-
internalStop(alias,false);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
55
|
|
|
47
56
|
function genOpsFull(data,tipo) {
|
|
48
57
|
var lista = [];
|
|
@@ -136,7 +145,6 @@ function build(data,model,user) {
|
|
|
136
145
|
module.exports = {
|
|
137
146
|
connect:connect,
|
|
138
147
|
connectAsync:connectAsync,
|
|
139
|
-
stop:stop,
|
|
140
148
|
stopCustom:stopCustom,
|
|
141
149
|
build:build,
|
|
142
150
|
genOps:genOps,
|
package/utils/query.js
CHANGED
|
@@ -42,6 +42,14 @@ var utils = {
|
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
}),
|
|
46
|
+
'updateManyAsync':(db,collection,data) => new Promise(resolve=>{
|
|
47
|
+
var listaOps = mdb.genOpsFull(data, 'save');
|
|
48
|
+
db.collection(collection).bulkWrite(listaOps, (err, result) => {
|
|
49
|
+
if (err) { console.log('Erro bulkwrite cad: ', err); }
|
|
50
|
+
var ids = result.getInsertedIds();
|
|
51
|
+
resolve({status:true,ids:ids});
|
|
52
|
+
});
|
|
45
53
|
})
|
|
46
54
|
}
|
|
47
55
|
|