-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
58 lines (51 loc) · 1.38 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*********************************************************************************
* File Name : db.js
* Created By : Svetlana Linuxenko, <[email protected]>, www.linuxenko.pro
* Creation Date : [2018-11-22 21:31]
* Last Modified : [2018-11-22 21:48]
* Description :
**********************************************************************************/
const mongoose = require('mongoose');
let dbInstance;
const Pong = mongoose.model('Pong', new mongoose.Schema({
bot: Number,
pet: Number,
fail: Number,
rice: Number,
price: Number,
buy: Number,
n: Number,
created: Date
}));
const Share = mongoose.model('Share', new mongoose.Schema({
id: Number,
donor: Number,
created: Date
}));
const Event = mongoose.model('Event', new mongoose.Schema({
id: Number,
owner_id: Number,
pet_id: Number,
purchase_price: String,
earned_amount: String,
profit_amount: String,
event_date: Number,
event_type: Number,
current_owner_id: Number
}));
async function instance() {
try {
if (!dbInstance) {
await mongoose.connect(process.env.MONGO, { useNewUrlParser: true });
dbInstance = mongoose.connection;
}
} catch(e) {
console.log(e);
return await instance();
}
return dbInstance;
}
module.exports.Pong = Pong;
module.exports.Share = Share;
module.exports.Event = Event;
module.exports.instance = (async () => await instance())();