add postgres support

This commit is contained in:
dm
2021-01-07 14:37:54 +01:00
parent 72221fcf0b
commit e04eedb2c4
3 changed files with 48 additions and 17 deletions

View File

@@ -7,6 +7,14 @@
"endpoint": "http://localhost:9666",
"invite_code": "top-sekrit",
"storage_type": "postgres",
"storage_config": {
"host": "localhost",
"database": "spacedeck",
"username": "postgres",
"password": "postgres"
},
"storage_local_path": "./storage",
"storage_local_db": "./database.sqlite",
"storage_region": "eu-central-1",

View File

@@ -6,24 +6,46 @@ function sequel_log(a,b,c) {
}
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
let sequelize;
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
storage: config.get('storage_local_db'),
logging: sequel_log,
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
if(config.has('storage_type') && config.get('storage_type') === 'postgres') {
console.log('connecting to postgres');
let postgresConfig = config.get('storage_config');
sequelize = new Sequelize(postgresConfig.database, postgresConfig.username, postgresConfig.password, {
host: postgresConfig.host,
dialect: 'postgres',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
logging: sequel_log,
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
} else {
console.log('connecting to sqlite');
sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
storage: config.get('storage_local_db'),
logging: sequel_log,
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
}
var User;
var Session;

View File

@@ -34,6 +34,7 @@
"node-phantom-simple": "2.2.4",
"node-server-screenshot": "^0.2.1",
"nodemailer": "^4.6.7",
"pg": "^8.5.1",
"phantomjs-prebuilt": "^2.1.16",
"read-chunk": "^2.1.0",
"request": "^2.88.0",