-
Notifications
You must be signed in to change notification settings - Fork 3
/
database.js
47 lines (42 loc) · 1.1 KB
/
database.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
const { Sequelize, DataTypes } = require('sequelize');
const pgHost = process.env.POSTGRES_HOST || "localhost"
const pgDatabase = process.env.POSTGRES_DB || "weather"
const pgPassword = process.env.POSTGRES_PASSWORD || "password"
const pgUser = process.env.POSTGRES_USER || "user"
const sequelize = new Sequelize(`postgres://${pgUser}:${pgPassword}@${pgHost}:5432/${pgDatabase}`, {
pool: {
max: 25,
min: 1,
acquire: 10000,
idle: 30000
}
});
const Weather = sequelize.define("Weather", {
city: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
primaryKey: true
},
weather: {
type: DataTypes.STRING,
allowNull: false
},
temperature: {
type: DataTypes.DOUBLE,
allowNull: false
},
nextUpdate: {
type: DataTypes.DATE,
allowNull: false
}
}, {
sequelize,
tableName: 'current_weather',
timestamps: false
});
(async () => {
await sequelize.sync({ force: true });
console.log("Database synchronized successfully.");
})();
module.exports = {Weather};