forked from tahsinature/sequelize-utility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (52 loc) · 1.58 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
52
53
54
class SequelizeHelper {
constructor(objectOfInstances, Sequelize) {
const arrayOfSequelizeInstances = Object.values(objectOfInstances); // Array of sequelize instance
arrayOfSequelizeInstances.forEach(instance => {
if (!(instance instanceof Sequelize)) {
throw new Error("Provided non-sequelize instance.");
}
});
this.connections = arrayOfSequelizeInstances;
}
establishConnections() {
return require("./methods/establishConnections")(this.connections);
}
resetTable(table) {
return require("./methods/resetTable")(table, this);
}
resetTablesExcepts(table, db) {
return require("./methods/resetTablesExcepts")(
table,
(db = this.connections.length === 1 ? this.connections[0] : db)
);
}
sync(connection) {
return require("./methods/sync")(
(connection =
this.connections.length === 1 ? this.connections[0] : connection)
);
}
syncForce(connection) {
return require("./methods/syncForce")(
(connection =
this.connections.length === 1 ? this.connections[0] : connection)
);
}
syncAllForce() {
return require("./methods/syncAllForce")(this.connections);
}
dropAllTablesFromConnection(connection) {
return require("./methods/dropAllTablesFromConnection")(connection);
}
dropAllTablesFromAllConnections() {
return require("./methods/dropAllTablesFromAllConnections")(
this.connections
);
}
closeAllConnections() {
return require("./methods/closeAllConnections")(
this.connections
);
}
}
module.exports.SequelizeHelper = SequelizeHelper;