rsibot-utils 1.2.7 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/db.js +24 -10
  2. package/package.json +1 -1
package/db.js CHANGED
@@ -58,14 +58,28 @@ mongoose
58
58
  console.log(err);
59
59
  });
60
60
 
61
- const HotCoin = mongoose.model('hot_coins', hotCoinsSchema);
62
- const ActiveCoin = mongoose.model('active_coins', activeSchema);
63
- const Queue = mongoose.model('queue_coins', queueSchema);
64
- const Historical = mongoose.model('historical_coins', historicalSchema);
61
+ const models = {
62
+ HotCoin:undefined,
63
+ ActiveCoin:undefined,
64
+ Queue:undefined,
65
+ Historical:undefined,
66
+ }
65
67
 
66
- module.exports = {
67
- HotCoin,
68
- ActiveCoin,
69
- Queue,
70
- Historical,
71
- };
68
+
69
+ const dbArray = [
70
+ { tableName:'hot_coins',name: 'HotCoin', schema: hotCoinsSchema },
71
+ { tableName:'active_coins',name: 'ActiveCoin', schema: activeSchema },
72
+ { tableName:'queue_coins',name: 'Queue', schema: queueSchema },
73
+ { tableName:'historical_coins',name: 'Historical', schema: historicalSchema },
74
+ ];
75
+
76
+ dbArray.forEach(({name,schema,tableName }) => {
77
+ if (mongoose.models[tableName]) {
78
+ models[name] = mongoose.model(tableName);
79
+ } else {
80
+ models[name] = mongoose.model(tableName, schema);
81
+ }
82
+ })
83
+
84
+
85
+ module.exports = models;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsibot-utils",
3
- "version": "1.2.7",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {