-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdb.js
75 lines (71 loc) · 2.25 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import IORedis from 'ioredis';
import { ServerApiVersion } from 'mongodb';
import mongoose from 'mongoose';
import auth from '../config/auth.config.js';
const db = {
mongoose,
authConnection: mongoose.createConnection(
`mongodb+srv://reading-list:${process.env.PASSWORD}@cluster0.ptjwk.mongodb.net/auth?retryWrites=true&w=majority`,
{
serverApi: ServerApiVersion.v1,
},
),
readingListConnection: mongoose.createConnection(
`mongodb+srv://reading-list:${process.env.PASSWORD}@cluster0.ptjwk.mongodb.net/reading-list?retryWrites=true&w=majority`,
{
serverApi: ServerApiVersion.v1,
},
),
microConnection: mongoose.createConnection(
`mongodb+srv://reading-list:${process.env.PASSWORD}@cluster0.ptjwk.mongodb.net/micro?retryWrites=true&w=majority`,
{
serverApi: ServerApiVersion.v1,
},
),
feedConnection: mongoose.createConnection(
`mongodb+srv://reading-list:${process.env.PASSWORD}@cluster0.ptjwk.mongodb.net/feed?retryWrites=true&w=majority`,
{
serverApi: ServerApiVersion.v1,
},
),
tagConnection: mongoose.createConnection(
`mongodb+srv://reading-list:${process.env.PASSWORD}@cluster0.ptjwk.mongodb.net/tags?retryWrites=true&w=majority`,
{
serverApi: ServerApiVersion.v1,
},
),
webmentionConnection: mongoose.createConnection(
`mongodb+srv://reading-list:${process.env.PASSWORD}@cluster0.ptjwk.mongodb.net/webmentions?retryWrites=true&w=majority`,
{
serverApi: ServerApiVersion.v1,
},
),
redis: new IORedis(
{ port: 32856, password: auth.redisPassword },
{ maxRetriesPerRequest: null },
),
};
db.initialize = async function () {
await Promise.all([
db.authConnection.asPromise(),
db.readingListConnection.asPromise(),
db.microConnection.asPromise(),
db.feedConnection.asPromise(),
db.tagConnection.asPromise(),
db.webmentionConnection.asPromise(),
]);
console.log('initialized');
};
db.gracefulClose = async function () {
await Promise.all([
db.authConnection.close(),
db.readingListConnection.close(),
db.microConnection.close(),
db.feedConnection.close(),
db.tagConnection.close(),
db.webmentionConnection.close(),
]);
console.log('db connections closed');
process.exit(0);
};
export default db;