Skip to content

Commit

Permalink
feat: get the database connection working
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Dec 7, 2021
1 parent 468aa35 commit 1750631
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var path = require('path');

module.exports = {
config: path.resolve('src', 'config', 'database.json'),
'migrations-path': path.resolve('migrations'),
'models-path': path.resolve('src', 'models'),
'seeders-path': path.resolve('seeders'),
};
6 changes: 3 additions & 3 deletions migrations/20211207145446-staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Staging', {
await queryInterface.createTable('Stagings', {
id: {
allowNull: false,
autoIncrement: true,
Expand All @@ -19,12 +19,12 @@ module.exports = {
type: Sequelize.STRING,
},
data: {
type: Sequelize.STRING,
type: Sequelize.STRING(10000),
},
});
},

down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Staging');
await queryInterface.dropTable('Stagings');
},
};
20 changes: 20 additions & 0 deletions src/config/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"development": {
"dialect": "sqlite",
"storage": "./data.sqlite3"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
11 changes: 10 additions & 1 deletion src/models/database.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
import { Sequelize } from 'sequelize';
export const sequelize = new Sequelize('sqlite::memory:');
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export const sequelize = new Sequelize({
dialect: 'sqlite',
storage: resolve(`${__dirname}../../../data.sqlite3`),
});
4 changes: 4 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import express from 'express';
import bodyParser from 'body-parser';
import { V1Router } from './v1';
import { sequelize } from '../models/database';

const app = express();

app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use('/v1', V1Router);

sequelize.authenticate().then(() => console.log('Connected to database'));

export default app;

0 comments on commit 1750631

Please sign in to comment.