forked from alwint3r/sequelize-datatable-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
72 lines (56 loc) · 1.26 KB
/
helper.js
File metadata and controls
72 lines (56 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const _ = require(`lodash`);
function boolify(booleanalike) {
if (typeof booleanalike === `boolean`) {
return booleanalike;
}
return booleanalike === `true`;
}
function getColumnName(field) {
return field.indexOf(`.`) > -1
? field.split(`.`).pop()
: field;
}
function boolAlike(value) {
return (value === `true` || value === `false`) || typeof value === `boolean`;
}
function getModelName(field) {
return field.indexOf(`.`) > -1
? field.split(`.`).shift()
: field;
}
function dfs(node, stack, visited) {
if (!node) {
return visited;
}
visited.push(node);
if (_.isArray(node.include) && node.include.length > 0) {
_.each(node.include, include => stack.push(include));
}
return dfs(stack.pop(), stack, visited);
}
function searchify(column) {
return column.indexOf(`.`) > -1
? `$${column}$`
: column;
}
function getModelAndColumn(column) {
if (column.indexOf(`.`) > -1) {
return column.split(`.`);
}
return [``, column];
}
function getDialectFromModel(model) {
const sequelize = model.QueryInterface.sequelize;
return sequelize.options.dialect;
}
module.exports = {
boolify,
getColumnName,
searchify,
dfs,
getModelName,
boolAlike,
getModelAndColumn,
getDialectFromModel,
};