aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2019-01-27 13:56:59 -0500
committerMark Powers <markppowers0@gmail.com>2019-01-27 13:56:59 -0500
commita16648b1af583e16e43b421bcd980ddcef304b51 (patch)
tree0ad38138dc12e35beaa0ed6659b6c62818be30d7 /src/index.js
parent6825b445ad975d603b4c212aed85f86559642e0f (diff)
Refactor bread to use vue.js
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/index.js b/src/index.js
index 767acb5..1dd00a0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,54 @@
const server = require('./server');
-server.setUpRoutes();
+const Sequelize = require('sequelize');
+const fs = require('fs');
+const path = require('path');
+
+const dbCreds = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))).database;
+
+const database = new Sequelize(dbCreds.database, dbCreds.user, dbCreds.password, {
+ logging(str) {
+ console.debug(`DB:${str}`);
+ },
+ dialectOptions: {
+ charset: 'utf8mb4',
+ multipleStatements: true,
+ },
+// host: dbCreds.host,
+ dialect: 'mysql',
+ pool: {
+ max: 5,
+ min: 0,
+ idle: 10000,
+ },
+});
+
+database.authenticate().then(() => {
+ console.debug(`database connection successful: ${dbCreds.database}`);
+}, (e) => console.log(e));
+
+async function sync(alter, force, callback) {
+ await database.sync({ alter, force, logging: console.log });
+}
+
+function setUpModels(){
+ const models = {
+ "posts": database.define('posts', {
+ description: {
+ type: Sequelize.STRING,
+ allowNull: false,
+ },
+ }),
+ "pictures": database.define('pictures', {
+ source: { type: Sequelize.TEXT, allowNull: false},
+ })
+ }
+ models.pictures.belongsTo(models.posts);
+ return models;
+}
+
+const models = setUpModels();
+sync();
+
+server.setUpRoutes(models);
server.listen();