@bbn/bbn 1.0.366 → 1.0.368
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 +73 -28
- package/package.json +1 -1
package/dist/db.js
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
1
37
|
import _ from './_.js';
|
|
2
38
|
import each from './fn/loop/each.js';
|
|
3
39
|
import iterate from './fn/loop/iterate.js';
|
|
@@ -5,13 +41,13 @@ import log from './fn/browser/log.js';
|
|
|
5
41
|
var idb = window['indexedDB'] || window['webkitIndexedDB'] || window['mozIndexedDB'] || window['OIndexedDB'] || window['msIndexedDB'];
|
|
6
42
|
var dbObject = function (dbName) {
|
|
7
43
|
var _this = this;
|
|
8
|
-
var conn = db._connections[dbName];
|
|
9
44
|
var structure = db._structures[dbName];
|
|
10
45
|
this.insert = function (table, data) {
|
|
11
46
|
if (!Array.isArray(data)) {
|
|
12
47
|
data = [data];
|
|
13
48
|
}
|
|
14
49
|
return new Promise(function (resolve) {
|
|
50
|
+
var conn = db._connections[dbName];
|
|
15
51
|
var tx = conn.transaction(table, "readwrite");
|
|
16
52
|
var store = tx.objectStore(table);
|
|
17
53
|
var res = data.length;
|
|
@@ -32,6 +68,7 @@ var dbObject = function (dbName) {
|
|
|
32
68
|
};
|
|
33
69
|
this.update = function (table, data, where) {
|
|
34
70
|
return new Promise(function (resolve) {
|
|
71
|
+
var conn = db._connections[dbName];
|
|
35
72
|
var tx = conn.transaction(table, "readwrite");
|
|
36
73
|
var store = tx.objectStore(table);
|
|
37
74
|
var arch = structure[table];
|
|
@@ -55,6 +92,7 @@ var dbObject = function (dbName) {
|
|
|
55
92
|
};
|
|
56
93
|
this.delete = function (table, where) {
|
|
57
94
|
return new Promise(function (resolve) {
|
|
95
|
+
var conn = db._connections[dbName];
|
|
58
96
|
var tx = conn.transaction(table, "readwrite");
|
|
59
97
|
var store = tx.objectStore(table);
|
|
60
98
|
var arch = structure[table];
|
|
@@ -84,34 +122,39 @@ var dbObject = function (dbName) {
|
|
|
84
122
|
});
|
|
85
123
|
});
|
|
86
124
|
};
|
|
87
|
-
this.select = function (table, fields, where, order, start, limit) {
|
|
88
|
-
var tx
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (fields.
|
|
103
|
-
res_1
|
|
125
|
+
this.select = function (table, fields, where, order, start, limit) { return __awaiter(_this, void 0, void 0, function () {
|
|
126
|
+
var conn, tx, store, arch, primary;
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
conn = db._connections[dbName];
|
|
129
|
+
tx = conn.transaction(table, "readonly");
|
|
130
|
+
store = tx.objectStore(table);
|
|
131
|
+
arch = structure[table];
|
|
132
|
+
primary = arch.keys.PRIMARY.columns.length > 1 ? arch.keys.PRIMARY.columns : arch.keys.PRIMARY.columns[0];
|
|
133
|
+
if (!where[primary]) {
|
|
134
|
+
throw new Error(_("No "));
|
|
135
|
+
}
|
|
136
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
137
|
+
var req = store.get(where[primary]);
|
|
138
|
+
req.onsuccess = function () {
|
|
139
|
+
var obj = req.result;
|
|
140
|
+
if (fields.length) {
|
|
141
|
+
var res_1 = {};
|
|
142
|
+
iterate(obj, function (v, n) {
|
|
143
|
+
if (fields.indexOf(n) > -1) {
|
|
144
|
+
res_1[n] = v;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return resolve(res_1);
|
|
104
148
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
};
|
|
149
|
+
else {
|
|
150
|
+
resolve(obj);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
})];
|
|
112
154
|
});
|
|
113
|
-
};
|
|
155
|
+
}); };
|
|
114
156
|
this.selectAll = function (table, fields, where, order, start, limit) {
|
|
157
|
+
var conn = db._connections[dbName];
|
|
115
158
|
var tx = conn.transaction(table, "read");
|
|
116
159
|
var store = tx.objectStore(table);
|
|
117
160
|
var arch = structure[table];
|
|
@@ -125,6 +168,7 @@ var dbObject = function (dbName) {
|
|
|
125
168
|
};
|
|
126
169
|
this.getColumnValues = function (table, field, where, order, start, limit) {
|
|
127
170
|
return new Promise(function (resolve) {
|
|
171
|
+
var conn = db._connections[dbName];
|
|
128
172
|
var tx = conn.transaction(table, "read");
|
|
129
173
|
var store = tx.objectStore(table);
|
|
130
174
|
});
|
|
@@ -164,9 +208,10 @@ var db = {
|
|
|
164
208
|
var obj = new dbObject(name);
|
|
165
209
|
resolve(obj);
|
|
166
210
|
};
|
|
167
|
-
return;
|
|
168
211
|
}
|
|
169
|
-
|
|
212
|
+
else {
|
|
213
|
+
resolve(new dbObject(name));
|
|
214
|
+
}
|
|
170
215
|
});
|
|
171
216
|
},
|
|
172
217
|
add: function (database, name, structure) {
|