forked from vikingeducation/project_mimirs_market
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepl.js
More file actions
50 lines (40 loc) · 1.26 KB
/
Copy pathrepl.js
File metadata and controls
50 lines (40 loc) · 1.26 KB
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
const mongoose = require('mongoose');
const repl = require('repl').start({});
const models = {
mongoose: require('./models/mongoose'),
sequelize: require('./models/sequelize')
};
const helpers = require('./helpers');
require('./mongo')().then(() => {
repl.context.models = models;
repl.context.helpers = helpers;
// ----------------------------------------
// Helpers
// ----------------------------------------
Object.keys(helpers).forEach((key) => {
repl.context[key] = helpers[key];
});
// ----------------------------------------
// Mongoose
// ----------------------------------------
Object.keys(models.mongoose).forEach((modelName) => {
repl.context[modelName] = mongoose.model(modelName);
});
// ----------------------------------------
// Sequelize
// ----------------------------------------
Object.keys(models.sequelize).forEach((modelName) => {
repl.context[modelName] = models.sequelize[modelName];
});
// ----------------------------------------
// Logging
// ----------------------------------------
repl.context.log = (data) => {
if (Array.isArray(data)) {
if (data.length && data[0].dataValues) {
data = data.map(item => item.dataValues);
}
}
console.log(data);
};
});