-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (39 loc) · 1.22 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Sequelize } from "sequelize";
import { generateStudentData, generateTeachersData } from "./data.js";
import {
createStudents,
createTeachersCourses,
assignStudentsToCourses,
defineTables
} from "./db-actions.js";
async function addStudents({ Person, Student }) {
const students = generateStudentData();
await createStudents({ Person, Student, students });
return students;
}
async function addTeachersCourses({ Teacher, Course, Person }) {
const teachers = generateTeachersData();
await createTeachersCourses({ Teacher, Course, Person, teachers });
return teachers;
}
(async () => {
console.log("Start...");
const sequalize = new Sequelize({
dialect: "sqlite",
storage: "tutorial.db",
define: {
freezeTableName: true,
createdAt: false,
updatedAt: false,
},
});
const { Person, Student, Teacher, Course, StudentToCourse } =
await defineTables(sequalize);
const students = await addStudents({ Person, Student });
const teachers = await addTeachersCourses({ Teacher, Course, Person });
await assignStudentsToCourses({ teachers, students, StudentToCourse });
await sequalize.sync();
console.log("Done...");
})().catch((err) => {
console.error(err);
});