-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
52 lines (47 loc) · 1.39 KB
/
test.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
const { Sequelize } = require('sequelize');
const { models } = require('./models/sequelize');
const sequelize = new Sequelize(process.env.DATABASE_URL, {
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: false // <<<<<<< YOU NEED THIS
}
}
});
sequelize.authenticate().then(() => {
console.log('Connection to postgres database has been established successfully.');
}).then(() => {
return models.User.findOrCreate({
where: { discordUID: 123 },
defaults: {
userName: "joe",
discordUID: 123
}
});
}).then((user, createdUser) => {
return models.Server.findOrCreate({
where: { discordServerID: 1 },
defaults: {
discordServerID: 1,
serverName: "server"
}
}).then((server, createdServer) => {
return [server, user];
});
}).then(([server, user]) => {
return models.Membership.findOrCreate({
where: { UserId: user[0].dataValues.id },
defaults: {
karma: 0,
ServerId: server[0].dataValues.id,
UserId: user[0].dataValues.id
}
});
}).then((membership, createdMembership) => {
console.log(membership);
console.log(createdMembership);
}).catch((err) => {
console.error('Unable to connect to the database:', err);
});