Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
πŸ‘žπŸ’– Configureable database path
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch (cute-ring) authored and Nathan Gerhart committed Mar 31, 2018
1 parent de2e2ee commit e978300
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const Postleaf = require(Path.join(__dirname, 'index.js'));
// Express app
const app = Express();

// Configuration options
const options = {
databasePath: Path.join(__dirname, 'data/database.sq3'),
}

Promise.resolve()
// Make sure .env exists
.then(() => {
Expand All @@ -25,7 +30,7 @@ Promise.resolve()
}
})
// Initialize Postleaf
.then(() => Postleaf(app))
.then(() => Postleaf(app, options))
.then(() => {

// Start sailing! βš“οΈ
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = function(app) {
module.exports = function(app, options) {

// Globals
global.__basedir = __dirname;
Expand Down Expand Up @@ -35,7 +35,7 @@ module.exports = function(app) {
const ErrorController = require(Path.join(__basedir, 'source/controllers/error_controller.js'));

// Database
const Database = require(Path.join(__basedir, 'source/modules/database.js'));
const Database = require(Path.join(__basedir, 'source/modules/database.js'))(options);
app.locals.Database = Database;

return Promise.resolve()
Expand Down
10 changes: 7 additions & 3 deletions source/modules/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const Mkdirp = require('mkdirp');
const Path = require('path');
const Promise = require('bluebird');
const Sequelize = require('sequelize');
let databasePath = Path.join(__basedir, 'data/database.sq3');

module.exports = function(options) {
options = options || {}
let databasePath = options.databasePath || Path.join(__basedir, 'data/database.sq3');

const sequelize = new Sequelize(null, null, null, {
dialect: 'sqlite',
Expand All @@ -30,7 +33,7 @@ let databasePath = Path.join(__basedir, 'data/database.sq3');
//
function init() {
// Create the data directory if it doesn't exist
let path = Path.join(__basedir, 'data');
let path = Path.dirname(databasePath);
Mkdirp.sync(path);

// Create missing tables and sync models
Expand Down Expand Up @@ -115,8 +118,9 @@ let databasePath = Path.join(__basedir, 'data/database.sq3');
setting.removeAttribute('id');

// Exports
module.exports = {
return {
init,
loadSettings,
sequelize
};
}

0 comments on commit e978300

Please sign in to comment.