@bbn/bbn 1.0.375 → 1.0.377
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/db.js +34 -2
- package/dist/fn/object/search.js +15 -1
- package/package.json +1 -1
package/dist/db.js
CHANGED
|
@@ -17,6 +17,38 @@ var transformResult = function (obj, fields) {
|
|
|
17
17
|
}
|
|
18
18
|
return obj;
|
|
19
19
|
};
|
|
20
|
+
var fieldsFromFilter = function (filter, fields) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (fields === void 0) { fields = []; }
|
|
23
|
+
if ((_a = filter === null || filter === void 0 ? void 0 : filter.conditions) === null || _a === void 0 ? void 0 : _a.length) {
|
|
24
|
+
filter.conditions.forEach(function (cond) {
|
|
25
|
+
if (cond.field && !fields.includes(cond.field)) {
|
|
26
|
+
fields.push(cond.field);
|
|
27
|
+
}
|
|
28
|
+
else if (cond.conditions) {
|
|
29
|
+
fieldsFromFilter(cond, fields);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else if (isObject(filter)) {
|
|
34
|
+
iterate(filter, function (v, n) {
|
|
35
|
+
if (!fields.includes(n)) {
|
|
36
|
+
fields.push(n);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else if (isArray(filter)) {
|
|
41
|
+
filter.forEach(function (cond) {
|
|
42
|
+
if (cond.field && !fields.includes(cond.field)) {
|
|
43
|
+
fields.push(cond.field);
|
|
44
|
+
}
|
|
45
|
+
else if (cond.conditions) {
|
|
46
|
+
fieldsFromFilter(cond, fields);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return fields;
|
|
51
|
+
};
|
|
20
52
|
var dbObject = function (dbName) {
|
|
21
53
|
var _this = this;
|
|
22
54
|
var conn = db._connections[dbName];
|
|
@@ -93,8 +125,8 @@ var dbObject = function (dbName) {
|
|
|
93
125
|
this.selectOne = function (table, field, where, order, start, limit) {
|
|
94
126
|
return new Promise(function (resolve) {
|
|
95
127
|
_this.selectAll(table, [field], where, order, start, 1).then(function (d) {
|
|
96
|
-
var _a;
|
|
97
|
-
resolve((_a = d[field]) !== null &&
|
|
128
|
+
var _a, _b;
|
|
129
|
+
resolve((_b = (_a = d === null || d === void 0 ? void 0 : d[0]) === null || _a === void 0 ? void 0 : _a[field]) !== null && _b !== void 0 ? _b : undefined);
|
|
98
130
|
});
|
|
99
131
|
});
|
|
100
132
|
};
|
package/dist/fn/object/search.js
CHANGED
|
@@ -136,12 +136,26 @@ export default function search(arr, prop, val, operator, startFrom, backward) {
|
|
|
136
136
|
filter = prop;
|
|
137
137
|
}
|
|
138
138
|
else if (isObject(prop)) {
|
|
139
|
-
if (
|
|
139
|
+
if ('field' in prop && 'value' in prop) {
|
|
140
140
|
filter = {
|
|
141
141
|
conditions: [prop],
|
|
142
142
|
logic: 'AND'
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
+
else if (!('conditions' in prop)) {
|
|
146
|
+
var conditions = [];
|
|
147
|
+
for (var p in prop) {
|
|
148
|
+
conditions.push({
|
|
149
|
+
field: p,
|
|
150
|
+
value: prop[p],
|
|
151
|
+
operator: '='
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
filter = {
|
|
155
|
+
conditions: conditions,
|
|
156
|
+
logic: 'AND'
|
|
157
|
+
};
|
|
158
|
+
}
|
|
145
159
|
else {
|
|
146
160
|
filter = prop;
|
|
147
161
|
}
|