bonsaif 1.10.39 → 1.10.40
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/README.md +0 -133
- package/lib/execute.js +0 -28
- package/lib/hookup/exec.js +2 -4
- package/lib/hookup/mariadb.js +10 -28
- package/lib/hookup/mongodb.js +177 -193
- package/lib/hookup/postgres.js +27 -35
- package/lib/hookup/redis.js +42 -162
- package/package.json +3 -6
- package/lib/hookup/mongoose.js +0 -988
- package/tests/README.md +0 -245
- package/tests/config.example.js +0 -61
- package/tests/docker-restart.sh +0 -20
- package/tests/docker-start.sh +0 -192
- package/tests/docker-stop.sh +0 -41
- package/tests/run-all-tests.js +0 -76
- package/tests/test-mariadb.js +0 -85
- package/tests/test-mongodb.js +0 -133
- package/tests/test-mongoose.js +0 -408
- package/tests/test-postgres.js +0 -84
- package/tests/test-redis.js +0 -85
package/lib/hookup/redis.js
CHANGED
|
@@ -129,28 +129,18 @@ const set=async(options, db, key, value, expire )=>{
|
|
|
129
129
|
if (expire>0){
|
|
130
130
|
redisConn.expire(key, expire, function(expErr,expRes){
|
|
131
131
|
resolve({"set":key, "expire":expire, "expRes":expRes, "err":err, "res":res, "time":utl.milisegundosASegundos(time)});
|
|
132
|
-
try{
|
|
133
|
-
exec.redisClose(redisConn);
|
|
134
|
-
}catch(e){
|
|
135
|
-
utl.log('err.set.close '+e);
|
|
136
|
-
}
|
|
137
132
|
});
|
|
138
133
|
}else{
|
|
139
134
|
resolve({"set":key, "expire":expire, "err":err, "res":res, "time":utl.milisegundosASegundos(time)});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
}
|
|
136
|
+
try{
|
|
137
|
+
exec.redisClose(redisConn);
|
|
138
|
+
}catch(e){
|
|
139
|
+
utl.log('err.set '+e);
|
|
145
140
|
}
|
|
146
141
|
});
|
|
147
142
|
}catch(e){
|
|
148
143
|
utl.log('err setKey'+e);
|
|
149
|
-
try{
|
|
150
|
-
exec.redisClose(redisConn);
|
|
151
|
-
}catch(closeErr){
|
|
152
|
-
utl.log('err.set.close.catch '+closeErr);
|
|
153
|
-
}
|
|
154
144
|
}
|
|
155
145
|
})
|
|
156
146
|
}
|
|
@@ -171,16 +161,11 @@ const get=async( options, db, key )=>{
|
|
|
171
161
|
try{
|
|
172
162
|
exec.redisClose(redisConn);
|
|
173
163
|
}catch(e){
|
|
174
|
-
utl.log('err.get
|
|
164
|
+
utl.log('err.get '+e);
|
|
175
165
|
}
|
|
176
166
|
});
|
|
177
167
|
}catch(e){
|
|
178
168
|
utl.log('err getKey'+e);
|
|
179
|
-
try{
|
|
180
|
-
exec.redisClose(redisConn);
|
|
181
|
-
}catch(closeErr){
|
|
182
|
-
utl.log('err.get.close.catch '+closeErr);
|
|
183
|
-
}
|
|
184
169
|
}
|
|
185
170
|
})
|
|
186
171
|
}
|
|
@@ -201,16 +186,11 @@ const type=async( options, db, key )=>{ // TYPE key
|
|
|
201
186
|
try{
|
|
202
187
|
exec.redisClose(redisConn);
|
|
203
188
|
}catch(e){
|
|
204
|
-
utl.log('err.type
|
|
189
|
+
utl.log('err.type '+e);
|
|
205
190
|
}
|
|
206
191
|
});
|
|
207
192
|
}catch(e){
|
|
208
193
|
utl.log('err type'+e);
|
|
209
|
-
try{
|
|
210
|
-
exec.redisClose(redisConn);
|
|
211
|
-
}catch(closeErr){
|
|
212
|
-
utl.log('err.type.close.catch '+closeErr);
|
|
213
|
-
}
|
|
214
194
|
}
|
|
215
195
|
})
|
|
216
196
|
}
|
|
@@ -218,6 +198,7 @@ const type=async( options, db, key )=>{ // TYPE key
|
|
|
218
198
|
|
|
219
199
|
const incrby=async(options, db, key,value,expire, counter )=>{
|
|
220
200
|
const exec = require("./exec");
|
|
201
|
+
const redisConn = await exec.redisConn(options);
|
|
221
202
|
expire = expire!=null?expire*1:0; // tls en segundo
|
|
222
203
|
counter = counter!=null?counter*1:0; // incremental
|
|
223
204
|
value = value ? !isNaN(value) ? value*1: 1 :1; // valor
|
|
@@ -228,23 +209,22 @@ const incrby=async(options, db, key,value,expire, counter )=>{
|
|
|
228
209
|
if (r.res==null){ // no existe
|
|
229
210
|
set(options,db,key,value,expire)
|
|
230
211
|
.then(r=>{
|
|
212
|
+
console.log({r});
|
|
231
213
|
const end = Date.now();
|
|
232
214
|
const time = end - start;
|
|
233
215
|
resolve({"set":key, "expire":expire, "err":null, "res":value, "counter":0, "time":utl.milisegundosASegundos(time)});
|
|
234
216
|
});
|
|
235
217
|
}else{
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
});
|
|
218
|
+
redisConn.select(db,function() { /* ... */ });
|
|
219
|
+
redisConn.incrby(key, counter, function (err, res) {
|
|
220
|
+
const end = Date.now();
|
|
221
|
+
const time = end - start;
|
|
222
|
+
resolve({"set":key, "expire":expire, "err":err, "res":res, "counter":counter, "time":utl.milisegundosASegundos(time)});
|
|
223
|
+
try{
|
|
224
|
+
exec.redisClose(redisConn);
|
|
225
|
+
}catch(e){
|
|
226
|
+
utl.log('err.incr '+e);
|
|
227
|
+
}
|
|
248
228
|
});
|
|
249
229
|
}
|
|
250
230
|
});
|
|
@@ -254,6 +234,7 @@ const incrby=async(options, db, key,value,expire, counter )=>{
|
|
|
254
234
|
|
|
255
235
|
const incrbyfloat=async( options,db, key, value, expire, counter )=>{
|
|
256
236
|
const exec = require("./exec");
|
|
237
|
+
const redisConn = await exec.redisConn(options);
|
|
257
238
|
expire = expire!=null?expire*1:0; // tls en segundo
|
|
258
239
|
counter = counter!=null?counter*1:0; // incremental
|
|
259
240
|
value = value ? !isNaN(value) ? value*1: 1 :1; // valor
|
|
@@ -264,26 +245,25 @@ const incrbyfloat=async( options,db, key, value, expire, counter )=>{
|
|
|
264
245
|
if (r.res==null){ // no existe
|
|
265
246
|
set(options,db,key,value,expire)
|
|
266
247
|
.then(r=>{
|
|
248
|
+
console.log({r});
|
|
267
249
|
const end = Date.now();
|
|
268
250
|
const time = end - start;
|
|
269
251
|
|
|
270
252
|
resolve({"set":key, "expire":expire, "err":null, "res":value, "counter":0, "time":utl.milisegundosASegundos(time)});
|
|
271
253
|
});
|
|
272
254
|
}else{
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const time = end - start;
|
|
255
|
+
redisConn.select(db,function() { /* ... */ });
|
|
256
|
+
redisConn.incrbyfloat(key,counter, function (err, res) {
|
|
257
|
+
const end = Date.now();
|
|
258
|
+
const time = end - start;
|
|
278
259
|
|
|
279
|
-
|
|
260
|
+
resolve({"set":key, "expire":expire, "err":err, "res":res, "counter":counter, "time":utl.milisegundosASegundos(time)});
|
|
280
261
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
});
|
|
262
|
+
try{
|
|
263
|
+
exec.redisClose(redisConn);
|
|
264
|
+
}catch(e){
|
|
265
|
+
utl.log('err.incr '+e);
|
|
266
|
+
}
|
|
287
267
|
});
|
|
288
268
|
}
|
|
289
269
|
});
|
|
@@ -316,11 +296,6 @@ const sadd=async(options, db, key, value )=>{ // SADD key member [member ...]
|
|
|
316
296
|
});
|
|
317
297
|
}catch(e){
|
|
318
298
|
utl.log('err sadd'+e);
|
|
319
|
-
try{
|
|
320
|
-
exec.redisClose(redisConn);
|
|
321
|
-
}catch(closeErr){
|
|
322
|
-
utl.log('err.sadd.close.catch '+closeErr);
|
|
323
|
-
}
|
|
324
299
|
}
|
|
325
300
|
})
|
|
326
301
|
}
|
|
@@ -350,11 +325,6 @@ const srem=async( options,db, key, value )=>{ //key member [member ...]
|
|
|
350
325
|
});
|
|
351
326
|
}catch(e){
|
|
352
327
|
utl.log('err del'+e);
|
|
353
|
-
try{
|
|
354
|
-
exec.redisClose(redisConn);
|
|
355
|
-
}catch(closeErr){
|
|
356
|
-
utl.log('err.srem.close.catch '+closeErr);
|
|
357
|
-
}
|
|
358
328
|
}
|
|
359
329
|
})
|
|
360
330
|
}
|
|
@@ -382,11 +352,6 @@ const smembers=async( options, db, key, toJson )=>{ // SMEMBERS key
|
|
|
382
352
|
});
|
|
383
353
|
}catch(e){
|
|
384
354
|
utl.log('err smembers'+e);
|
|
385
|
-
try{
|
|
386
|
-
exec.redisClose(redisConn);
|
|
387
|
-
}catch(closeErr){
|
|
388
|
-
utl.log('err.smembers.close.catch '+closeErr);
|
|
389
|
-
}
|
|
390
355
|
}
|
|
391
356
|
})
|
|
392
357
|
}
|
|
@@ -417,11 +382,6 @@ const sinter=async(options, db, keys)=>{ // SINTER key [key ...]
|
|
|
417
382
|
});
|
|
418
383
|
}catch(e){
|
|
419
384
|
utl.log('err sinter'+e);
|
|
420
|
-
try{
|
|
421
|
-
exec.redisClose(redisConn);
|
|
422
|
-
}catch(closeErr){
|
|
423
|
-
utl.log('err.sinter.close.catch '+closeErr);
|
|
424
|
-
}
|
|
425
385
|
}
|
|
426
386
|
})
|
|
427
387
|
}
|
|
@@ -447,11 +407,6 @@ const scard=async( options, db, key )=>{ // SCARD key
|
|
|
447
407
|
});
|
|
448
408
|
}catch(e){
|
|
449
409
|
utl.log('err scard'+e);
|
|
450
|
-
try{
|
|
451
|
-
exec.redisClose(redisConn);
|
|
452
|
-
}catch(closeErr){
|
|
453
|
-
utl.log('err.scard.close.catch '+closeErr);
|
|
454
|
-
}
|
|
455
410
|
}
|
|
456
411
|
})
|
|
457
412
|
}
|
|
@@ -483,11 +438,6 @@ const sunionstore=async( options, db, destination, keys )=>{ // SUNIONSTORE des
|
|
|
483
438
|
});
|
|
484
439
|
}catch(e){
|
|
485
440
|
utl.log('err sunionstore'+e);
|
|
486
|
-
try{
|
|
487
|
-
exec.redisClose(redisConn);
|
|
488
|
-
}catch(closeErr){
|
|
489
|
-
utl.log('err.sunionstore.close.catch '+closeErr);
|
|
490
|
-
}
|
|
491
441
|
}
|
|
492
442
|
})
|
|
493
443
|
}
|
|
@@ -519,11 +469,6 @@ const hset=async( options,db, key, values )=>{ // HSET key field value [ field
|
|
|
519
469
|
});
|
|
520
470
|
}catch(e){
|
|
521
471
|
utl.log('err hset'+e);
|
|
522
|
-
try{
|
|
523
|
-
exec.redisClose(redisConn);
|
|
524
|
-
}catch(closeErr){
|
|
525
|
-
utl.log('err.hset.close.catch '+closeErr);
|
|
526
|
-
}
|
|
527
472
|
}
|
|
528
473
|
})
|
|
529
474
|
}
|
|
@@ -547,11 +492,6 @@ const hgetall=async(options, db, key )=>{ // HGETALL key
|
|
|
547
492
|
});
|
|
548
493
|
}catch(e){
|
|
549
494
|
utl.log('err hgetall'+e);
|
|
550
|
-
try{
|
|
551
|
-
exec.redisClose(redisConn);
|
|
552
|
-
}catch(closeErr){
|
|
553
|
-
utl.log('err.hgetall.close.catch '+closeErr);
|
|
554
|
-
}
|
|
555
495
|
}
|
|
556
496
|
})
|
|
557
497
|
}
|
|
@@ -590,11 +530,6 @@ const hmget=async(options, db, key, fields )=>{ // HMGET key field [field ...]
|
|
|
590
530
|
});
|
|
591
531
|
}catch(e){
|
|
592
532
|
utl.log('err hmget'+e);
|
|
593
|
-
try{
|
|
594
|
-
exec.redisClose(redisConn);
|
|
595
|
-
}catch(closeErr){
|
|
596
|
-
utl.log('err.hmget.close.catch '+closeErr);
|
|
597
|
-
}
|
|
598
533
|
}
|
|
599
534
|
})
|
|
600
535
|
}
|
|
@@ -619,11 +554,6 @@ const del=async( options,db, key )=>{ //DEL key [key ...]
|
|
|
619
554
|
});
|
|
620
555
|
}catch(e){
|
|
621
556
|
utl.log('err del'+e);
|
|
622
|
-
try{
|
|
623
|
-
exec.redisClose(redisConn);
|
|
624
|
-
}catch(closeErr){
|
|
625
|
-
utl.log('err.del.close.catch '+closeErr);
|
|
626
|
-
}
|
|
627
557
|
}
|
|
628
558
|
})
|
|
629
559
|
}
|
|
@@ -734,16 +664,11 @@ const expireat=async(options, db, key, expire )=>{
|
|
|
734
664
|
try{
|
|
735
665
|
exec.redisClose(redisConn);
|
|
736
666
|
}catch(e){
|
|
737
|
-
utl.log('err.expireat
|
|
667
|
+
utl.log('err.expireat:'+e);
|
|
738
668
|
}
|
|
739
669
|
});
|
|
740
670
|
}catch(e){
|
|
741
671
|
utl.log('err expireat:'+e);
|
|
742
|
-
try{
|
|
743
|
-
exec.redisClose(redisConn);
|
|
744
|
-
}catch(closeErr){
|
|
745
|
-
utl.log('err.expireat.close.catch:'+closeErr);
|
|
746
|
-
}
|
|
747
672
|
}
|
|
748
673
|
})
|
|
749
674
|
}
|
|
@@ -762,28 +687,18 @@ const setnx=async(options, db, key, value, expire )=>{
|
|
|
762
687
|
if (expire>0){
|
|
763
688
|
redisConn.expire(key, expire, function(expErr,expRes){
|
|
764
689
|
resolve({"set":key, "expire":expire, "expRes":expRes, "err":err, "res":res, "time":utl.milisegundosASegundos(time)});
|
|
765
|
-
try{
|
|
766
|
-
exec.redisClose(redisConn);
|
|
767
|
-
}catch(e){
|
|
768
|
-
utl.log('err.setnx.close '+e);
|
|
769
|
-
}
|
|
770
690
|
});
|
|
771
691
|
}else{
|
|
772
692
|
resolve({"set":key, "expire":expire, "err":err, "res":res, "time":utl.milisegundosASegundos(time)});
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
693
|
+
}
|
|
694
|
+
try{
|
|
695
|
+
exec.redisClose(redisConn);
|
|
696
|
+
}catch(e){
|
|
697
|
+
utl.log('err.set '+e);
|
|
778
698
|
}
|
|
779
699
|
});
|
|
780
700
|
}catch(e){
|
|
781
701
|
utl.log('err setKey'+e);
|
|
782
|
-
try{
|
|
783
|
-
exec.redisClose(redisConn);
|
|
784
|
-
}catch(closeErr){
|
|
785
|
-
utl.log('err.setnx.close.catch '+closeErr);
|
|
786
|
-
}
|
|
787
702
|
}
|
|
788
703
|
})
|
|
789
704
|
}
|
|
@@ -810,28 +725,18 @@ const hsetnx=async( options,db, key, values, expire )=>{ // HSET key field valu
|
|
|
810
725
|
if (expire>0){
|
|
811
726
|
redisConn.expire(key, expire, function(expErr,expRes){
|
|
812
727
|
resolve({"hsetnx":key, "expire":expire, "expRes":expRes, "err":err, "res":res, "value":values, "time":utl.milisegundosASegundos(time)});
|
|
813
|
-
try{
|
|
814
|
-
exec.redisClose(redisConn);
|
|
815
|
-
}catch(e){
|
|
816
|
-
utl.log('err.hsetnx.close '+e);
|
|
817
|
-
}
|
|
818
728
|
});
|
|
819
729
|
}else{
|
|
820
730
|
resolve({"hsetnx":key, "expire":expire, "err":err, "res":res, "value":values, "time":utl.milisegundosASegundos(time)});
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
731
|
+
}
|
|
732
|
+
try{
|
|
733
|
+
exec.redisClose(redisConn);
|
|
734
|
+
}catch(e){
|
|
735
|
+
utl.log('err.hsetnx '+e);
|
|
826
736
|
}
|
|
827
737
|
});
|
|
828
738
|
}catch(e){
|
|
829
739
|
utl.log('err hsetnx'+e);
|
|
830
|
-
try{
|
|
831
|
-
exec.redisClose(redisConn);
|
|
832
|
-
}catch(closeErr){
|
|
833
|
-
utl.log('err.hsetnx.close.catch '+closeErr);
|
|
834
|
-
}
|
|
835
740
|
}
|
|
836
741
|
})
|
|
837
742
|
}
|
|
@@ -863,11 +768,6 @@ const hmset=async( options,db, key, values )=>{ // HSET key field value [ field
|
|
|
863
768
|
});
|
|
864
769
|
}catch(e){
|
|
865
770
|
utl.log('err hmset'+e);
|
|
866
|
-
try{
|
|
867
|
-
exec.redisClose(redisConn);
|
|
868
|
-
}catch(closeErr){
|
|
869
|
-
utl.log('err.hmset.close.catch '+closeErr);
|
|
870
|
-
}
|
|
871
771
|
}
|
|
872
772
|
})
|
|
873
773
|
}
|
|
@@ -894,11 +794,6 @@ const expire=async( options,db, key, expire )=>{ // EXPIRE key seconds
|
|
|
894
794
|
});
|
|
895
795
|
}catch(e){
|
|
896
796
|
utl.log('err expire'+e);
|
|
897
|
-
try{
|
|
898
|
-
exec.redisClose(redisConn);
|
|
899
|
-
}catch(closeErr){
|
|
900
|
-
utl.log('err.expire.close.catch '+closeErr);
|
|
901
|
-
}
|
|
902
797
|
}
|
|
903
798
|
})
|
|
904
799
|
}
|
|
@@ -924,11 +819,6 @@ const lrange=async( options, db, key, start, stop )=>{ // LRANGE key start stop
|
|
|
924
819
|
});
|
|
925
820
|
}catch(e){
|
|
926
821
|
utl.log('err lrange'+e);
|
|
927
|
-
try{
|
|
928
|
-
exec.redisClose(redisConn);
|
|
929
|
-
}catch(closeErr){
|
|
930
|
-
utl.log('err.lrange.close.catch '+closeErr);
|
|
931
|
-
}
|
|
932
822
|
}
|
|
933
823
|
})
|
|
934
824
|
}
|
|
@@ -953,11 +843,6 @@ const keys=async( options, db, pattern )=>{ // KEYS pattern
|
|
|
953
843
|
});
|
|
954
844
|
}catch(e){
|
|
955
845
|
utl.log('err keys'+e);
|
|
956
|
-
try{
|
|
957
|
-
exec.redisClose(redisConn);
|
|
958
|
-
}catch(closeErr){
|
|
959
|
-
utl.log('err.keys.close.catch '+closeErr);
|
|
960
|
-
}
|
|
961
846
|
}
|
|
962
847
|
})
|
|
963
848
|
}
|
|
@@ -981,11 +866,6 @@ const dbsize=async( options, db )=>{ // DBSIZE
|
|
|
981
866
|
});
|
|
982
867
|
}catch(e){
|
|
983
868
|
utl.log('err dbsize'+e);
|
|
984
|
-
try{
|
|
985
|
-
exec.redisClose(redisConn);
|
|
986
|
-
}catch(closeErr){
|
|
987
|
-
utl.log('err.dbsize.close.catch '+closeErr);
|
|
988
|
-
}
|
|
989
869
|
}
|
|
990
870
|
})
|
|
991
871
|
}
|
package/package.json
CHANGED
|
@@ -12,12 +12,9 @@
|
|
|
12
12
|
"request": "^2.88.2",
|
|
13
13
|
"ua-parser-js": "^1.0.37"
|
|
14
14
|
},
|
|
15
|
-
"optionalDependencies": {
|
|
16
|
-
"mongoose": "^8.23.1"
|
|
17
|
-
},
|
|
18
15
|
"name": "bonsaif",
|
|
19
16
|
"description": "bonsaif is a library to connect to bonsaif apis",
|
|
20
|
-
"version": "1.10.
|
|
17
|
+
"version": "1.10.40",
|
|
21
18
|
"main": "index.js",
|
|
22
19
|
"directories": {
|
|
23
20
|
"lib": "lib"
|
|
@@ -35,10 +32,10 @@
|
|
|
35
32
|
"query",
|
|
36
33
|
"redis",
|
|
37
34
|
"mongodb",
|
|
38
|
-
"mongoose",
|
|
39
35
|
"mariadb",
|
|
40
36
|
"postgres"
|
|
41
37
|
],
|
|
42
38
|
"author": "vsampablo",
|
|
43
|
-
"license": "MIT"
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"devDependencies": {}
|
|
44
41
|
}
|