Skip to content

Commit 745a52b

Browse files
committed
defined the databse models
1 parent d9740f8 commit 745a52b

File tree

10 files changed

+458
-1
lines changed

10 files changed

+458
-1
lines changed

Projects/BooksLibrary/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Projects/BooksLibrary/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/express-fileupload": "^1.2.2",
1818
"@types/jsonwebtoken": "^8.5.8",
1919
"@types/node": "^17.0.21",
20+
"@types/uuid": "^8.3.4",
2021
"@typescript-eslint/eslint-plugin": "^5.13.0",
2122
"@typescript-eslint/parser": "^5.13.0",
2223
"eslint": "^8.10.0",

Projects/BooksLibrary/src/database/sql/sequelize/database.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class DbConfig {
1717
password: process.env.DB_USER_PASSWORD,
1818
database: process.env.DB_NAME,
1919
host: process.env.DB_HOST,
20-
dialect: 'mysql',
20+
dialect: 'postgres',
2121
pool: {
2222
max: 20,
2323
min: 0,
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* eslint-disable indent */
2+
import {
3+
Column,
4+
CreatedAt,
5+
DataType,
6+
DeletedAt,
7+
IsUUID,
8+
Length,
9+
Model,
10+
PrimaryKey,
11+
Table,
12+
UpdatedAt,
13+
} from 'sequelize-typescript';
14+
import { v4 } from 'uuid';
15+
16+
@Table({
17+
timestamps: true,
18+
modelName: 'Person',
19+
tableName: 'persons',
20+
paranoid: true,
21+
freezeTableName: true,
22+
})
23+
export default class Author extends Model {
24+
@IsUUID(4)
25+
@PrimaryKey
26+
@Column({
27+
type: DataType.UUID,
28+
defaultValue: () => {
29+
return v4();
30+
},
31+
allowNull: false,
32+
})
33+
id: string;
34+
35+
@Length({ max: 16 })
36+
@Column({
37+
type: DataType.STRING(16),
38+
allowNull: true,
39+
})
40+
Prefix: string;
41+
42+
@Length({ max: 70 })
43+
@Column({
44+
type: DataType.STRING(70),
45+
allowNull: false,
46+
})
47+
FirstName: string;
48+
49+
@Length({ max: 70 })
50+
@Column({
51+
type: DataType.STRING(70),
52+
allowNull: true,
53+
})
54+
MiddleName: string;
55+
56+
@Length({ max: 70 })
57+
@Column({
58+
type: DataType.STRING(70),
59+
allowNull: true,
60+
})
61+
LastName: string;
62+
63+
@Column
64+
@CreatedAt
65+
CreatedAt: Date;
66+
67+
@UpdatedAt
68+
UpdatedAt: Date;
69+
70+
@DeletedAt
71+
DeletedAt: Date;
72+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* eslint-disable indent */
2+
import {
3+
BelongsTo,
4+
Column,
5+
CreatedAt,
6+
DataType,
7+
DeletedAt,
8+
ForeignKey,
9+
IsUUID,
10+
Model,
11+
PrimaryKey,
12+
Table,
13+
UpdatedAt,
14+
} from 'sequelize-typescript';
15+
import { v4 } from 'uuid';
16+
import BookCopy from './book.copy.model';
17+
import User from './user.model';
18+
19+
@Table({
20+
timestamps: true,
21+
modelName: 'BookBorrowLog',
22+
tableName: 'book_borrow_log',
23+
paranoid: true,
24+
freezeTableName: true,
25+
})
26+
export default class BookBorrowLog extends Model {
27+
@IsUUID(4)
28+
@PrimaryKey
29+
@Column({
30+
type: DataType.UUID,
31+
defaultValue: () => {
32+
return v4();
33+
},
34+
allowNull: false,
35+
})
36+
id: string;
37+
38+
@IsUUID(4)
39+
@ForeignKey(() => BookCopy)
40+
@Column({
41+
type: DataType.UUID,
42+
allowNull: false,
43+
})
44+
BookCopyId: string;
45+
46+
@BelongsTo(() => BookCopy)
47+
BookCopy: BookCopy;
48+
49+
@IsUUID(4)
50+
@ForeignKey(() => User)
51+
@Column({
52+
type: DataType.UUID,
53+
allowNull: false,
54+
})
55+
BookBorrowedByUserId: string;
56+
57+
@BelongsTo(() => User)
58+
BookBorrowerUser: User;
59+
60+
@Column({
61+
type: DataType.DATE,
62+
allowNull: false,
63+
})
64+
BorrowedAt: Date;
65+
66+
@Column({
67+
type: DataType.DATE,
68+
allowNull: true,
69+
})
70+
ReturnedAt: Date;
71+
72+
@Column
73+
@CreatedAt
74+
CreatedAt: Date;
75+
76+
@UpdatedAt
77+
UpdatedAt: Date;
78+
79+
@DeletedAt
80+
DeletedAt: Date;
81+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-disable indent */
2+
import {
3+
BelongsTo,
4+
Column,
5+
CreatedAt,
6+
DataType,
7+
DeletedAt,
8+
ForeignKey,
9+
IsUUID,
10+
Model,
11+
PrimaryKey,
12+
Table,
13+
UpdatedAt,
14+
} from 'sequelize-typescript';
15+
import { v4 } from 'uuid';
16+
import Book from './book.model';
17+
18+
@Table({
19+
timestamps: true,
20+
modelName: 'BookCopy',
21+
tableName: 'book_copy',
22+
paranoid: true,
23+
freezeTableName: true,
24+
})
25+
export default class BookCopy extends Model {
26+
@IsUUID(4)
27+
@PrimaryKey
28+
@Column({
29+
type: DataType.UUID,
30+
defaultValue: () => {
31+
return v4();
32+
},
33+
allowNull: false,
34+
})
35+
id: string;
36+
37+
@IsUUID(4)
38+
@ForeignKey(() => Book)
39+
@Column({
40+
type: DataType.UUID,
41+
allowNull: false,
42+
})
43+
BookId: string;
44+
45+
@BelongsTo(() => Book)
46+
Book: Book;
47+
48+
@Column
49+
@CreatedAt
50+
CreatedAt: Date;
51+
52+
@UpdatedAt
53+
UpdatedAt: Date;
54+
55+
@DeletedAt
56+
DeletedAt: Date;
57+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* eslint-disable indent */
2+
import {
3+
BelongsTo,
4+
Column,
5+
CreatedAt,
6+
DataType,
7+
DeletedAt,
8+
ForeignKey,
9+
IsUUID,
10+
Length,
11+
Model,
12+
PrimaryKey,
13+
Table,
14+
UpdatedAt,
15+
} from 'sequelize-typescript';
16+
import { v4 } from 'uuid';
17+
import Author from './author.model';
18+
19+
@Table({
20+
timestamps: true,
21+
modelName: 'Book',
22+
tableName: 'book',
23+
paranoid: true,
24+
freezeTableName: true,
25+
})
26+
export default class Book extends Model {
27+
@IsUUID(4)
28+
@PrimaryKey
29+
@Column({
30+
type: DataType.UUID,
31+
defaultValue: () => {
32+
return v4();
33+
},
34+
allowNull: false,
35+
})
36+
id: string;
37+
38+
@Length({ max: 70 })
39+
@Column({
40+
type: DataType.STRING(70),
41+
allowNull: false,
42+
})
43+
Name: string;
44+
45+
@Length({ max: 70 })
46+
@Column({
47+
type: DataType.STRING(70),
48+
allowNull: true,
49+
})
50+
Summary: string;
51+
52+
@Column({
53+
type: DataType.DATE,
54+
allowNull: false,
55+
})
56+
PublishedAt: Date;
57+
58+
@IsUUID(4)
59+
@ForeignKey(() => Author)
60+
@Column({
61+
type: DataType.UUID,
62+
allowNull: false,
63+
})
64+
AuthorId: string;
65+
66+
@BelongsTo(() => Author)
67+
Author: Author;
68+
69+
@Column
70+
@CreatedAt
71+
CreatedAt: Date;
72+
73+
@UpdatedAt
74+
UpdatedAt: Date;
75+
76+
@DeletedAt
77+
DeletedAt: Date;
78+
}

Projects/BooksLibrary/src/database/sql/sequelize/models/index.ts

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable indent */
2+
import {
3+
Column,
4+
CreatedAt,
5+
DataType,
6+
DeletedAt,
7+
IsUUID,
8+
Length,
9+
Model,
10+
PrimaryKey,
11+
Table,
12+
UpdatedAt,
13+
} from 'sequelize-typescript';
14+
import { v4 } from 'uuid';
15+
16+
@Table({
17+
timestamps: true,
18+
modelName: 'Role',
19+
tableName: 'role',
20+
paranoid: true,
21+
freezeTableName: true,
22+
})
23+
export default class Role extends Model {
24+
@IsUUID(4)
25+
@PrimaryKey
26+
@Column({
27+
type: DataType.UUID,
28+
defaultValue: () => {
29+
return v4();
30+
},
31+
allowNull: false,
32+
})
33+
id: string;
34+
35+
@Length({ max: 70 })
36+
@Column({
37+
type: DataType.STRING(70),
38+
allowNull: false,
39+
})
40+
RoleName: string;
41+
42+
@Column
43+
@CreatedAt
44+
CreatedAt: Date;
45+
46+
@UpdatedAt
47+
UpdatedAt: Date;
48+
49+
@DeletedAt
50+
DeletedAt: Date;
51+
}

0 commit comments

Comments
 (0)