Files
bch-email-api/bin/iredmail.js
T

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-01-21 17:17:26 -08:00
/*
A class for connecting to and controlling the postgres database of an iredmail
email server.
*/
'use strict'
const Sequelize = require('sequelize')
const config = require('../config')
// Models
const UsedQuota = require('../postgres/models/used-quota')
2019-01-22 15:26:50 -08:00
const Mailbox = require('../postgres/models/mailbox')
2019-01-22 16:43:59 -08:00
const Forwardings = require('../postgres/models/forwardings')
2019-01-21 17:17:26 -08:00
class IRedMail {
constructor () {
// Instantiate and initialize sequelize.
this.sequelize = this.initSequelize()
// Load the models
this.models = {
2019-01-22 15:26:50 -08:00
usedQuota: new UsedQuota(this.sequelize),
2019-01-22 16:43:59 -08:00
mailbox: new Mailbox(this.sequelize),
forwardings: new Forwardings(this.sequelize)
2019-01-21 17:17:26 -08:00
}
}
// Returns an instance of the sequelize class, configured for the Postgres
// database defined in the config object.
initSequelize () {
return new Sequelize('vmail', config.postgresUser, config.postgresPass, {
host: config.postgresHost,
dialect: 'postgres',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
})
}
}
module.exports = IRedMail