Skip to content

Commit

Permalink
add connection and first model
Browse files Browse the repository at this point in the history
  • Loading branch information
arthursvpb committed Jul 7, 2023
1 parent 31edba2 commit 8b6b662
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 16 deletions.
62 changes: 48 additions & 14 deletions api/package-lock.json

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

3 changes: 2 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"dependencies": {
"express": "^4.18.1",
"sequelize": "^6.21.4"
"sequelize": "^6.21.4",
"sequelize-typescript": "^2.1.5"
},
"devDependencies": {
"@types/express": "^4.17.13",
Expand Down
11 changes: 11 additions & 0 deletions api/src/database/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SequelizeOptions } from 'sequelize-typescript';

const sequelizeOptions: SequelizeOptions = {
database: 'pc_db',
dialect: 'mysql',
username: 'root',
password: 'docker',
models: [`${__dirname}/../models/*.ts`],
};

export default sequelizeOptions;
5 changes: 5 additions & 0 deletions api/src/database/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Sequelize } from 'sequelize-typescript';

import config from './config';

export const sequelize = new Sequelize(config);
41 changes: 40 additions & 1 deletion api/src/models/User/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
//
import {
Table,
Column,
Model,
CreatedAt,
UpdatedAt,
DataType,
Unique,
} from 'sequelize-typescript';

export interface IUser {
id: string;
name: string;
email: string;
password: string;
created_at?: Date;
updated_at?: Date;
}

@Table
export default class User extends Model {
@Column({ primaryKey: true, allowNull: false })
id: string;

@Column(DataType.TEXT)
name: string;

@Unique
@Column(DataType.TEXT)
email: string;

@Column(DataType.UUIDV4)
password: string;

@CreatedAt
created_at: Date;

@UpdatedAt
updated_at: Date;
}

0 comments on commit 8b6b662

Please sign in to comment.