mysql2-core 0.3.4 → 0.3.5
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/lib/build.js +88 -102
- package/lib/index.js +635 -849
- package/package.json +1 -1
- package/tsconfig.json +4 -4
package/lib/build.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function param(i) {
|
|
1
|
+
export function param(i) {
|
|
4
2
|
return "?";
|
|
5
3
|
}
|
|
6
|
-
|
|
7
|
-
function params(length, from) {
|
|
4
|
+
export function params(length, from) {
|
|
8
5
|
if (from == null) {
|
|
9
6
|
from = 0;
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
for (
|
|
8
|
+
const ps = [];
|
|
9
|
+
for (let i = 1; i <= length; i++) {
|
|
13
10
|
ps.push(param(i + from));
|
|
14
11
|
}
|
|
15
12
|
return ps;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var k = ks_1[_i];
|
|
28
|
-
var attr = attrs[k];
|
|
14
|
+
export function metadata(attrs) {
|
|
15
|
+
const mp = {};
|
|
16
|
+
const ks = Object.keys(attrs);
|
|
17
|
+
const ats = [];
|
|
18
|
+
const bools = [];
|
|
19
|
+
const fields = [];
|
|
20
|
+
const m = { keys: ats, fields };
|
|
21
|
+
let isMap = false;
|
|
22
|
+
for (const k of ks) {
|
|
23
|
+
const attr = attrs[k];
|
|
29
24
|
attr.name = k;
|
|
30
25
|
if (attr.key) {
|
|
31
26
|
ats.push(attr);
|
|
@@ -39,8 +34,8 @@ function metadata(attrs) {
|
|
|
39
34
|
if (attr.version) {
|
|
40
35
|
m.version = k;
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
const field = attr.column ? attr.column : k;
|
|
38
|
+
const s = field.toLowerCase();
|
|
44
39
|
if (s !== k) {
|
|
45
40
|
mp[s] = k;
|
|
46
41
|
isMap = true;
|
|
@@ -54,56 +49,54 @@ function metadata(attrs) {
|
|
|
54
49
|
}
|
|
55
50
|
return m;
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
52
|
+
export function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
59
53
|
if (!i) {
|
|
60
54
|
i = 1;
|
|
61
55
|
}
|
|
62
56
|
if (!buildParam) {
|
|
63
57
|
buildParam = param;
|
|
64
58
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
for (
|
|
73
|
-
|
|
74
|
-
var attr = attrs[k];
|
|
59
|
+
const ks = Object.keys(attrs);
|
|
60
|
+
const pks = [];
|
|
61
|
+
const cols = [];
|
|
62
|
+
const values = [];
|
|
63
|
+
const args = [];
|
|
64
|
+
let isVersion = false;
|
|
65
|
+
const o = obj;
|
|
66
|
+
for (const k of ks) {
|
|
67
|
+
const attr = attrs[k];
|
|
75
68
|
attr.name = k;
|
|
76
69
|
if (attr.key) {
|
|
77
70
|
pks.push(attr);
|
|
78
71
|
}
|
|
79
|
-
|
|
72
|
+
let v = o[k];
|
|
80
73
|
if (v == null) {
|
|
81
74
|
v = attr.default;
|
|
82
75
|
}
|
|
83
76
|
if (v !== undefined && v != null && !attr.ignored && !attr.noinsert) {
|
|
84
|
-
|
|
77
|
+
const field = attr.column ? attr.column : k;
|
|
85
78
|
cols.push(field);
|
|
86
79
|
if (k === ver) {
|
|
87
80
|
isVersion = true;
|
|
88
|
-
values.push(
|
|
81
|
+
values.push(`${1}`);
|
|
89
82
|
}
|
|
90
83
|
else {
|
|
91
84
|
if (v === "") {
|
|
92
|
-
values.push(
|
|
85
|
+
values.push(`''`);
|
|
93
86
|
}
|
|
94
87
|
else if (typeof v === "number") {
|
|
95
88
|
values.push(toString(v));
|
|
96
89
|
}
|
|
97
90
|
else {
|
|
98
|
-
|
|
91
|
+
const p = buildParam(i++);
|
|
99
92
|
values.push(p);
|
|
100
93
|
if (typeof v === "boolean") {
|
|
101
94
|
if (v === true) {
|
|
102
|
-
|
|
95
|
+
const v2 = attr.true ? attr.true : `'1'`;
|
|
103
96
|
args.push(v2);
|
|
104
97
|
}
|
|
105
98
|
else {
|
|
106
|
-
|
|
99
|
+
const v2 = attr.false ? attr.false : `'0'`;
|
|
107
100
|
args.push(v2);
|
|
108
101
|
}
|
|
109
102
|
}
|
|
@@ -115,35 +108,34 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
115
108
|
}
|
|
116
109
|
}
|
|
117
110
|
if (!isVersion && ver && ver.length > 0) {
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
const attr = attrs[ver];
|
|
112
|
+
const field = attr.column ? attr.column : ver;
|
|
120
113
|
cols.push(field);
|
|
121
|
-
values.push(
|
|
114
|
+
values.push(`${1}`);
|
|
122
115
|
}
|
|
123
116
|
if (pks.length === 0) {
|
|
124
117
|
if (cols.length === 0) {
|
|
125
118
|
return { query: "", params: args };
|
|
126
119
|
}
|
|
127
120
|
else {
|
|
128
|
-
|
|
121
|
+
const q = `insert into ${table}(${cols.join(",")})values(${values.join(",")})`;
|
|
129
122
|
return { query: q, params: args };
|
|
130
123
|
}
|
|
131
124
|
}
|
|
132
125
|
else {
|
|
133
|
-
|
|
134
|
-
for (
|
|
135
|
-
|
|
136
|
-
var v = o[k];
|
|
126
|
+
const colSet = [];
|
|
127
|
+
for (const k of ks) {
|
|
128
|
+
const v = o[k];
|
|
137
129
|
if (v !== undefined) {
|
|
138
|
-
|
|
130
|
+
const attr = attrs[k];
|
|
139
131
|
if (attr && !attr.key && !attr.ignored && !attr.noupdate) {
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
const field = attr.column ? attr.column : k;
|
|
133
|
+
let x;
|
|
142
134
|
if (v === null) {
|
|
143
135
|
x = "null";
|
|
144
136
|
}
|
|
145
137
|
else if (v === "") {
|
|
146
|
-
x =
|
|
138
|
+
x = `''`;
|
|
147
139
|
}
|
|
148
140
|
else if (typeof v === "number") {
|
|
149
141
|
x = toString(v);
|
|
@@ -152,11 +144,11 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
152
144
|
x = buildParam(i++);
|
|
153
145
|
if (typeof v === "boolean") {
|
|
154
146
|
if (v === true) {
|
|
155
|
-
|
|
147
|
+
const v2 = attr.true ? "" + attr.true : `'1'`;
|
|
156
148
|
args.push(v2);
|
|
157
149
|
}
|
|
158
150
|
else {
|
|
159
|
-
|
|
151
|
+
const v2 = attr.false ? "" + attr.false : `'0'`;
|
|
160
152
|
args.push(v2);
|
|
161
153
|
}
|
|
162
154
|
}
|
|
@@ -164,66 +156,63 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
164
156
|
args.push(v);
|
|
165
157
|
}
|
|
166
158
|
}
|
|
167
|
-
colSet.push(field
|
|
159
|
+
colSet.push(`${field}=${x}`);
|
|
168
160
|
}
|
|
169
161
|
}
|
|
170
162
|
}
|
|
171
163
|
if (colSet.length === 0) {
|
|
172
|
-
|
|
164
|
+
const q = `insert ignore into ${table}(${cols.join(",")})values(${values.join(",")})`;
|
|
173
165
|
return { query: q, params: args };
|
|
174
166
|
}
|
|
175
167
|
else {
|
|
176
|
-
|
|
168
|
+
const q = `insert into ${table}(${cols.join(",")})values(${values.join(",")}) on duplicate key update ${colSet.join(",")}`;
|
|
177
169
|
return { query: q, params: args };
|
|
178
170
|
}
|
|
179
171
|
}
|
|
180
172
|
}
|
|
181
|
-
|
|
182
|
-
function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
173
|
+
export function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
183
174
|
if (!buildParam) {
|
|
184
175
|
buildParam = param;
|
|
185
176
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
for (
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var attr = attrs[k];
|
|
199
|
-
var v = o[k];
|
|
177
|
+
const sts = [];
|
|
178
|
+
const ks = Object.keys(attrs);
|
|
179
|
+
for (const obj of objs) {
|
|
180
|
+
let i = 1;
|
|
181
|
+
const cols = [];
|
|
182
|
+
const values = [];
|
|
183
|
+
const args = [];
|
|
184
|
+
let isVersion = false;
|
|
185
|
+
const o = obj;
|
|
186
|
+
for (const k of ks) {
|
|
187
|
+
const attr = attrs[k];
|
|
188
|
+
let v = o[k];
|
|
200
189
|
if (v == null) {
|
|
201
190
|
v = attr.default;
|
|
202
191
|
}
|
|
203
192
|
if (v != null && v !== undefined && !attr.ignored && !attr.noinsert) {
|
|
204
|
-
|
|
193
|
+
const field = attr.column ? attr.column : k;
|
|
205
194
|
cols.push(field);
|
|
206
195
|
if (k === ver) {
|
|
207
196
|
isVersion = true;
|
|
208
|
-
values.push(
|
|
197
|
+
values.push(`${1}`);
|
|
209
198
|
}
|
|
210
199
|
else {
|
|
211
200
|
if (v === "") {
|
|
212
|
-
values.push(
|
|
201
|
+
values.push(`''`);
|
|
213
202
|
}
|
|
214
203
|
else if (typeof v === "number") {
|
|
215
204
|
values.push(toString(v));
|
|
216
205
|
}
|
|
217
206
|
else {
|
|
218
|
-
|
|
207
|
+
const p = buildParam(i++);
|
|
219
208
|
values.push(p);
|
|
220
209
|
if (typeof v === "boolean") {
|
|
221
210
|
if (v === true) {
|
|
222
|
-
|
|
211
|
+
const v2 = attr.true ? attr.true : `'1'`;
|
|
223
212
|
args.push(v2);
|
|
224
213
|
}
|
|
225
214
|
else {
|
|
226
|
-
|
|
215
|
+
const v2 = attr.false ? attr.false : `'0'`;
|
|
227
216
|
args.push(v2);
|
|
228
217
|
}
|
|
229
218
|
}
|
|
@@ -235,25 +224,24 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
235
224
|
}
|
|
236
225
|
}
|
|
237
226
|
if (!isVersion && ver && ver.length > 0) {
|
|
238
|
-
|
|
239
|
-
|
|
227
|
+
const attr = attrs[ver];
|
|
228
|
+
const field = attr.column ? attr.column : ver;
|
|
240
229
|
cols.push(field);
|
|
241
|
-
values.push(
|
|
230
|
+
values.push(`${1}`);
|
|
242
231
|
}
|
|
243
|
-
|
|
244
|
-
for (
|
|
245
|
-
|
|
246
|
-
var v = o[k];
|
|
232
|
+
const colSet = [];
|
|
233
|
+
for (const k of ks) {
|
|
234
|
+
const v = o[k];
|
|
247
235
|
if (v !== undefined) {
|
|
248
|
-
|
|
236
|
+
const attr = attrs[k];
|
|
249
237
|
if (attr && !attr.key && !attr.ignored && k !== ver && !attr.noupdate) {
|
|
250
|
-
|
|
251
|
-
|
|
238
|
+
const field = attr.column ? attr.column : k;
|
|
239
|
+
let x;
|
|
252
240
|
if (v === null) {
|
|
253
241
|
x = "null";
|
|
254
242
|
}
|
|
255
243
|
else if (v === "") {
|
|
256
|
-
x =
|
|
244
|
+
x = `''`;
|
|
257
245
|
}
|
|
258
246
|
else if (typeof v === "number") {
|
|
259
247
|
x = toString(v);
|
|
@@ -262,11 +250,11 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
262
250
|
x = buildParam(i++);
|
|
263
251
|
if (typeof v === "boolean") {
|
|
264
252
|
if (v === true) {
|
|
265
|
-
|
|
253
|
+
const v2 = attr.true ? "" + attr.true : `'1'`;
|
|
266
254
|
args.push(v2);
|
|
267
255
|
}
|
|
268
256
|
else {
|
|
269
|
-
|
|
257
|
+
const v2 = attr.false ? "" + attr.false : `'0'`;
|
|
270
258
|
args.push(v2);
|
|
271
259
|
}
|
|
272
260
|
}
|
|
@@ -274,30 +262,28 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
274
262
|
args.push(v);
|
|
275
263
|
}
|
|
276
264
|
}
|
|
277
|
-
colSet.push(field
|
|
265
|
+
colSet.push(`${field}=${x}`);
|
|
278
266
|
}
|
|
279
267
|
}
|
|
280
268
|
}
|
|
281
269
|
if (colSet.length === 0) {
|
|
282
|
-
|
|
283
|
-
|
|
270
|
+
const q = `insert ignore into ${table}(${cols.join(",")})values(${values.join(",")});`;
|
|
271
|
+
const smt = { query: q, params: args };
|
|
284
272
|
sts.push(smt);
|
|
285
273
|
}
|
|
286
274
|
else {
|
|
287
|
-
|
|
288
|
-
|
|
275
|
+
const q = `insert into ${table}(${cols.join(",")})values(${values.join(",")}) on duplicate key update ${colSet.join(",")};`;
|
|
276
|
+
const smt = { query: q, params: args };
|
|
289
277
|
sts.push(smt);
|
|
290
278
|
}
|
|
291
279
|
}
|
|
292
280
|
return sts;
|
|
293
281
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
var x = "" + v;
|
|
282
|
+
const n = "NaN";
|
|
283
|
+
export function toString(v) {
|
|
284
|
+
let x = "" + v;
|
|
298
285
|
if (x === n) {
|
|
299
286
|
x = "null";
|
|
300
287
|
}
|
|
301
288
|
return x;
|
|
302
289
|
}
|
|
303
|
-
exports.toString = toString;
|