From 18d09b49be259bb0d328faec024661b66537ca81 Mon Sep 17 00:00:00 2001 From: dm Date: Thu, 7 Jan 2021 15:26:13 +0100 Subject: [PATCH] unify config, add postgres decimal fix --- config/default.json | 11 +++++----- models/db.js | 50 +++++++++++++-------------------------------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/config/default.json b/config/default.json index f9062ba..fcc459e 100644 --- a/config/default.json +++ b/config/default.json @@ -7,11 +7,12 @@ "endpoint": "http://localhost:9666", "invite_code": "top-sekrit", - "storage_type": "postgres", - "storage_postgres_host": "localhost", - "storage_postgres_database": "spacedeck", - "storage_postgres_username": "postgres", - "storage_postgres_password": "postgres", + "storage_dialect": "sqlite", + + "storage_host": "localhost", + "storage_database": "spacedeck", + "storage_username": "username", + "storage_password": "password", "storage_local_path": "./storage", "storage_local_db": "./database.sqlite", diff --git a/models/db.js b/models/db.js index 40eb52d..03de63d 100644 --- a/models/db.js +++ b/models/db.js @@ -6,50 +6,28 @@ function sequel_log(a,b,c) { } const Sequelize = require('sequelize'); -let sequelize; - -if(config.has('storage_type') && config.get('storage_type') === 'postgres') { - console.log('connecting to postgres'); - sequelize = new Sequelize( - config.get('storage_postgres_database'), - config.get('storage_postgres_username'), - config.get('storage_postgres_password'), - { - host: config.get('storage_postgres_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', - +const sequelize = new Sequelize( + config.get('storage_database'), + config.get('storage_username'), + config.get('storage_password'), + { + host: config.get('storage_host'), + dialect: config.get('storage_dialect'), 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 - }); -} + operatorsAliases: false, + // SQLite only + storage: config.get('storage_local_db') + } +); +// https://github.com/sequelize/sequelize/issues/8019#issuecomment-384316346 +Sequelize.postgres.DECIMAL.parse = function (value) { return parseFloat(value); }; var User; var Session;