-
Notifications
You must be signed in to change notification settings - Fork 1
/
techDb.js
47 lines (41 loc) · 1.38 KB
/
techDb.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
const Sequelize = require('sequelize');
const migration = require('./lib/migration');
const wrapSql = require('./lib/wrapSql');
const lockService = require('./lib/lockService');
module.exports = configuration => {
const sequelize = new Sequelize(
configuration.db.connection.database,
configuration.db.connection.username,
configuration.db.connection.password,
configuration.db.connection.options
);
const lockServiceInstance = lockService({ sequelize, Sequelize });
const migrationInstance = migration({
sequelize,
Sequelize,
lockService: lockServiceInstance,
config: configuration.db.migration
});
return {
// The DB instance
sequelize,
// The library that could be used to get all available DataTypes
Sequelize,
// Instance used to migrate the database
migration: migrationInstance,
// Lock service
lockService: lockServiceInstance,
dao: entityName => {
const wrapper = wrapSql({ sequelize, entityName });
return {
find: wrapper.wrapByName('find', 'Read'),
findAll: wrapper.wrapByName('findAll', 'Read'),
findAndCountAll: wrapper.wrapByName('findAndCountAll', 'Read'),
sum: wrapper.wrapByName('sum', 'Read'),
create: wrapper.wrapByName('create', 'Create'),
destroy: wrapper.wrapByName('destroy', 'Delete'),
update: wrapper.wrapUpdate()
};
}
};
};