Skip to content

Commit

Permalink
add sequelize connection
Browse files Browse the repository at this point in the history
  • Loading branch information
arthursvpb committed Jul 12, 2023
1 parent 15ee54e commit 2188729
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
13 changes: 13 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"express": "^4.18.1",
"express-async-errors": "^3.1.1",
"mysql2": "^3.5.0",
"sequelize": "^6.21.4",
"sequelize-typescript": "^2.1.5"
Expand Down
4 changes: 1 addition & 3 deletions api/src/database/connection.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Sequelize } from 'sequelize-typescript';

export const sequelize = new Sequelize({
port: 3306,
host: '127.0.0.1',
host: 'pc_db',
database: 'pc_db',
dialect: 'mysql',
username: 'root',
password: 'docker',
models: [`${__dirname}/../models/**/*.ts`],
logging: true,
});
9 changes: 2 additions & 7 deletions api/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import express from 'express';
import 'express-async-errors';

import { sequelize } from './database/connection';

const app = express();

(async () => {
try {
await sequelize.authenticate();
} catch (error) {
console.error(error);
}
})();
sequelize.authenticate({ logging: query => console.info(`▶️: ${query}`) });

app.get('/', (_, res) => res.send('Hello World!'));

Expand Down

0 comments on commit 2188729

Please sign in to comment.