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