-
Notifications
You must be signed in to change notification settings - Fork 49
/
database.js
43 lines (38 loc) · 1002 Bytes
/
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
const Sequelize = require('sequelize')
const sequelize = new Sequelize('status', 'server', '!$%openvpn1', {
dialect: 'sqlite',
storage: './data.sqlite',
logging: false,
pool: {max: 5, min: 0, idle: 10000}
})
const mkId = () => ({
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
})
const Log = sequelize.define('Log', {
id: mkId(),
timestamp: {type: Sequelize.INTEGER},
server: {type: Sequelize.INTEGER},
pub: {type: Sequelize.STRING},
vpn: {type: Sequelize.STRING},
node: {type: Sequelize.STRING},
event: {type: Sequelize.STRING}
}, {
freezeTableName: true,
timestamps: false,
tableName: 'Log'
})
const Client = sequelize.define('Clent', {
id: mkId(),
server: {type: Sequelize.INTEGER},
name: {type: Sequelize.STRING},
sent: {type: Sequelize.INTEGER, defaultValue: 0},
received: {type: Sequelize.INTEGER, defaultValue: 0}
})
module.exports = {
init: () => Promise.all([Log.sync(), Client.sync()]),
Log,
Client,
op: Sequelize.Op
}