mirror of
https://github.com/Permissionless-Software-Foundation/bch-email-api.git
synced 2026-09-21 16:52:04 -07:00
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
/*
|
|
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')
|
|
const Mailbox = require('../postgres/models/mailbox')
|
|
const Forwardings = require('../postgres/models/forwardings')
|
|
|
|
class IRedMail {
|
|
constructor () {
|
|
// Instantiate and initialize sequelize.
|
|
this.sequelize = this.initSequelize()
|
|
|
|
// Load the models
|
|
this.models = {
|
|
usedQuota: new UsedQuota(this.sequelize),
|
|
mailbox: new Mailbox(this.sequelize),
|
|
forwardings: new Forwardings(this.sequelize)
|
|
}
|
|
}
|
|
|
|
// 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
|