query-core 0.0.4
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/README.md +1 -0
- package/lib/batch.js +262 -0
- package/lib/build.js +784 -0
- package/lib/index.js +7 -0
- package/package.json +27 -0
- package/src/batch.ts +218 -0
- package/src/build.ts +683 -0
- package/src/index.ts +17 -0
- package/src/metadata.ts +73 -0
- package/tsconfig.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# query
|
package/lib/batch.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var build_1 = require("./build");
|
|
4
|
+
var SqlInserter = (function () {
|
|
5
|
+
function SqlInserter(exec, table, attributes, param, map) {
|
|
6
|
+
this.exec = exec;
|
|
7
|
+
this.table = table;
|
|
8
|
+
this.attributes = attributes;
|
|
9
|
+
this.param = param;
|
|
10
|
+
this.map = map;
|
|
11
|
+
this.write = this.write.bind(this);
|
|
12
|
+
var x = build_1.version(attributes);
|
|
13
|
+
if (x) {
|
|
14
|
+
this.version = x.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
SqlInserter.prototype.write = function (obj) {
|
|
18
|
+
if (!obj) {
|
|
19
|
+
return Promise.resolve(0);
|
|
20
|
+
}
|
|
21
|
+
var obj2 = obj;
|
|
22
|
+
if (this.map) {
|
|
23
|
+
obj2 = this.map(obj);
|
|
24
|
+
}
|
|
25
|
+
var stmt = build_1.buildToInsert(obj2, this.table, this.attributes, this.param, this.version);
|
|
26
|
+
if (stmt) {
|
|
27
|
+
return this.exec(stmt.query, stmt.params);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return Promise.resolve(0);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return SqlInserter;
|
|
34
|
+
}());
|
|
35
|
+
exports.SqlInserter = SqlInserter;
|
|
36
|
+
var SqlUpdater = (function () {
|
|
37
|
+
function SqlUpdater(exec, table, attributes, param, map) {
|
|
38
|
+
this.exec = exec;
|
|
39
|
+
this.table = table;
|
|
40
|
+
this.attributes = attributes;
|
|
41
|
+
this.param = param;
|
|
42
|
+
this.map = map;
|
|
43
|
+
this.write = this.write.bind(this);
|
|
44
|
+
var x = build_1.version(attributes);
|
|
45
|
+
if (x) {
|
|
46
|
+
this.version = x.name;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
SqlUpdater.prototype.write = function (obj) {
|
|
50
|
+
if (!obj) {
|
|
51
|
+
return Promise.resolve(0);
|
|
52
|
+
}
|
|
53
|
+
var obj2 = obj;
|
|
54
|
+
if (this.map) {
|
|
55
|
+
obj2 = this.map(obj);
|
|
56
|
+
}
|
|
57
|
+
var stmt = build_1.buildToUpdate(obj2, this.table, this.attributes, this.param, this.version);
|
|
58
|
+
if (stmt) {
|
|
59
|
+
return this.exec(stmt.query, stmt.params);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return Promise.resolve(0);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return SqlUpdater;
|
|
66
|
+
}());
|
|
67
|
+
exports.SqlUpdater = SqlUpdater;
|
|
68
|
+
var SqlBatchInserter = (function () {
|
|
69
|
+
function SqlBatchInserter(exec, table, attributes, param, map) {
|
|
70
|
+
this.exec = exec;
|
|
71
|
+
this.table = table;
|
|
72
|
+
this.attributes = attributes;
|
|
73
|
+
this.param = param;
|
|
74
|
+
this.map = map;
|
|
75
|
+
this.write = this.write.bind(this);
|
|
76
|
+
var x = build_1.version(attributes);
|
|
77
|
+
if (x) {
|
|
78
|
+
this.version = x.name;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
SqlBatchInserter.prototype.write = function (objs) {
|
|
82
|
+
if (!objs || objs.length === 0) {
|
|
83
|
+
return Promise.resolve(0);
|
|
84
|
+
}
|
|
85
|
+
var list = objs;
|
|
86
|
+
if (this.map) {
|
|
87
|
+
list = [];
|
|
88
|
+
for (var _i = 0, objs_1 = objs; _i < objs_1.length; _i++) {
|
|
89
|
+
var obj = objs_1[_i];
|
|
90
|
+
var obj2 = this.map(obj);
|
|
91
|
+
list.push(obj2);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var stmt = build_1.buildToInsertBatch(list, this.table, this.attributes, this.param, this.version);
|
|
95
|
+
if (stmt) {
|
|
96
|
+
return this.exec(stmt.query, stmt.params);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return Promise.resolve(0);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return SqlBatchInserter;
|
|
103
|
+
}());
|
|
104
|
+
exports.SqlBatchInserter = SqlBatchInserter;
|
|
105
|
+
var SqlBatchUpdater = (function () {
|
|
106
|
+
function SqlBatchUpdater(execBatch, table, attributes, param, notSkipInvalid, map) {
|
|
107
|
+
this.execBatch = execBatch;
|
|
108
|
+
this.table = table;
|
|
109
|
+
this.attributes = attributes;
|
|
110
|
+
this.param = param;
|
|
111
|
+
this.notSkipInvalid = notSkipInvalid;
|
|
112
|
+
this.map = map;
|
|
113
|
+
this.write = this.write.bind(this);
|
|
114
|
+
var x = build_1.version(attributes);
|
|
115
|
+
if (x) {
|
|
116
|
+
this.version = x.name;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
SqlBatchUpdater.prototype.write = function (objs) {
|
|
120
|
+
if (!objs || objs.length === 0) {
|
|
121
|
+
return Promise.resolve(0);
|
|
122
|
+
}
|
|
123
|
+
var list = objs;
|
|
124
|
+
if (this.map) {
|
|
125
|
+
list = [];
|
|
126
|
+
for (var _i = 0, objs_2 = objs; _i < objs_2.length; _i++) {
|
|
127
|
+
var obj = objs_2[_i];
|
|
128
|
+
var obj2 = this.map(obj);
|
|
129
|
+
list.push(obj2);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
var stmts = build_1.buildToUpdateBatch(list, this.table, this.attributes, this.param, this.notSkipInvalid);
|
|
133
|
+
if (stmts && stmts.length > 0) {
|
|
134
|
+
return this.execBatch(stmts);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return Promise.resolve(0);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
return SqlBatchUpdater;
|
|
141
|
+
}());
|
|
142
|
+
exports.SqlBatchUpdater = SqlBatchUpdater;
|
|
143
|
+
var StreamInserter = (function () {
|
|
144
|
+
function StreamInserter(exec, table, attributes, param, size, toDB) {
|
|
145
|
+
this.exec = exec;
|
|
146
|
+
this.table = table;
|
|
147
|
+
this.attributes = attributes;
|
|
148
|
+
this.param = param;
|
|
149
|
+
this.list = [];
|
|
150
|
+
this.size = 0;
|
|
151
|
+
this.write = this.write.bind(this);
|
|
152
|
+
this.flush = this.flush.bind(this);
|
|
153
|
+
this.map = toDB;
|
|
154
|
+
var x = build_1.version(attributes);
|
|
155
|
+
if (x) {
|
|
156
|
+
this.version = x.name;
|
|
157
|
+
}
|
|
158
|
+
if (size !== undefined && size > 0) {
|
|
159
|
+
this.size = size;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
StreamInserter.prototype.write = function (obj) {
|
|
163
|
+
if (!obj) {
|
|
164
|
+
return Promise.resolve(0);
|
|
165
|
+
}
|
|
166
|
+
var obj2 = obj;
|
|
167
|
+
if (this.map) {
|
|
168
|
+
obj2 = this.map(obj);
|
|
169
|
+
this.list.push(obj2);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
this.list.push(obj);
|
|
173
|
+
}
|
|
174
|
+
if (this.list.length < this.size) {
|
|
175
|
+
return Promise.resolve(0);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return this.flush();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
StreamInserter.prototype.flush = function () {
|
|
182
|
+
var _this = this;
|
|
183
|
+
if (!this.list || this.list.length === 0) {
|
|
184
|
+
return Promise.resolve(0);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
var total_1 = this.list.length;
|
|
188
|
+
var stmt = build_1.buildToInsertBatch(this.list, this.table, this.attributes, this.param, this.version);
|
|
189
|
+
if (stmt) {
|
|
190
|
+
return this.exec(stmt.query, stmt.params).then(function (r) {
|
|
191
|
+
_this.list = [];
|
|
192
|
+
return total_1;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return Promise.resolve(0);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
return StreamInserter;
|
|
201
|
+
}());
|
|
202
|
+
exports.StreamInserter = StreamInserter;
|
|
203
|
+
var StreamUpdater = (function () {
|
|
204
|
+
function StreamUpdater(execBatch, table, attributes, param, size, toDB) {
|
|
205
|
+
this.execBatch = execBatch;
|
|
206
|
+
this.table = table;
|
|
207
|
+
this.attributes = attributes;
|
|
208
|
+
this.param = param;
|
|
209
|
+
this.list = [];
|
|
210
|
+
this.size = 0;
|
|
211
|
+
this.write = this.write.bind(this);
|
|
212
|
+
this.flush = this.flush.bind(this);
|
|
213
|
+
this.map = toDB;
|
|
214
|
+
var x = build_1.version(attributes);
|
|
215
|
+
if (x) {
|
|
216
|
+
this.version = x.name;
|
|
217
|
+
}
|
|
218
|
+
if (size !== undefined && size > 0) {
|
|
219
|
+
this.size = size;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
StreamUpdater.prototype.write = function (obj) {
|
|
223
|
+
if (!obj) {
|
|
224
|
+
return Promise.resolve(0);
|
|
225
|
+
}
|
|
226
|
+
var obj2 = obj;
|
|
227
|
+
if (this.map) {
|
|
228
|
+
obj2 = this.map(obj);
|
|
229
|
+
this.list.push(obj2);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.list.push(obj);
|
|
233
|
+
}
|
|
234
|
+
if (this.list.length < this.size) {
|
|
235
|
+
return Promise.resolve(0);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return this.flush();
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
StreamUpdater.prototype.flush = function () {
|
|
242
|
+
var _this = this;
|
|
243
|
+
if (!this.list || this.list.length === 0) {
|
|
244
|
+
return Promise.resolve(0);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
var total_2 = this.list.length;
|
|
248
|
+
var stmt = build_1.buildToUpdateBatch(this.list, this.table, this.attributes, this.param);
|
|
249
|
+
if (stmt) {
|
|
250
|
+
return this.execBatch(stmt).then(function (r) {
|
|
251
|
+
_this.list = [];
|
|
252
|
+
return total_2;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return Promise.resolve(0);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
return StreamUpdater;
|
|
261
|
+
}());
|
|
262
|
+
exports.StreamUpdater = StreamUpdater;
|