mysql2-core 0.2.2 → 0.2.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/lib/build.js +39 -39
- package/lib/index.js +162 -170
- package/package.json +2 -1
- package/src/build.ts +153 -153
- package/src/index.ts +481 -437
- package/src/metadata.ts +83 -66
package/lib/build.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function param(i) {
|
|
4
|
-
return
|
|
4
|
+
return "?";
|
|
5
5
|
}
|
|
6
6
|
exports.param = param;
|
|
7
7
|
function params(length, from) {
|
|
@@ -33,13 +33,13 @@ function metadata(attrs) {
|
|
|
33
33
|
if (!attr.ignored) {
|
|
34
34
|
fields.push(k);
|
|
35
35
|
}
|
|
36
|
-
if (attr.type ===
|
|
36
|
+
if (attr.type === "boolean") {
|
|
37
37
|
bools.push(attr);
|
|
38
38
|
}
|
|
39
39
|
if (attr.version) {
|
|
40
40
|
m.version = k;
|
|
41
41
|
}
|
|
42
|
-
var field =
|
|
42
|
+
var field = attr.column ? attr.column : k;
|
|
43
43
|
var s = field.toLowerCase();
|
|
44
44
|
if (s !== k) {
|
|
45
45
|
mp[s] = k;
|
|
@@ -81,29 +81,29 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
81
81
|
v = attr.default;
|
|
82
82
|
}
|
|
83
83
|
if (v !== undefined && v != null && !attr.ignored && !attr.noinsert) {
|
|
84
|
-
var field =
|
|
84
|
+
var field = attr.column ? attr.column : k;
|
|
85
85
|
cols.push(field);
|
|
86
86
|
if (k === ver) {
|
|
87
87
|
isVersion = true;
|
|
88
88
|
values.push("" + 1);
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
if (v ===
|
|
91
|
+
if (v === "") {
|
|
92
92
|
values.push("''");
|
|
93
93
|
}
|
|
94
|
-
else if (typeof v ===
|
|
94
|
+
else if (typeof v === "number") {
|
|
95
95
|
values.push(toString(v));
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
98
|
var p = buildParam(i++);
|
|
99
99
|
values.push(p);
|
|
100
|
-
if (typeof v ===
|
|
100
|
+
if (typeof v === "boolean") {
|
|
101
101
|
if (v === true) {
|
|
102
|
-
var v2 =
|
|
102
|
+
var v2 = attr.true ? attr.true : "'1'";
|
|
103
103
|
args.push(v2);
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
var v2 =
|
|
106
|
+
var v2 = attr.false ? attr.false : "'0'";
|
|
107
107
|
args.push(v2);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -116,7 +116,7 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
116
116
|
}
|
|
117
117
|
if (!isVersion && ver && ver.length > 0) {
|
|
118
118
|
var attr = attrs[ver];
|
|
119
|
-
var field =
|
|
119
|
+
var field = attr.column ? attr.column : ver;
|
|
120
120
|
cols.push(field);
|
|
121
121
|
values.push("" + 1);
|
|
122
122
|
}
|
|
@@ -125,7 +125,7 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
125
125
|
return undefined;
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
|
-
var q = "insert into " + table + "(" + cols.join(
|
|
128
|
+
var q = "insert into " + table + "(" + cols.join(",") + ")values(" + values.join(",") + ")";
|
|
129
129
|
return { query: q, params: args };
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -137,26 +137,26 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
137
137
|
if (v !== undefined) {
|
|
138
138
|
var attr = attrs[k];
|
|
139
139
|
if (attr && !attr.key && !attr.ignored && !attr.noupdate) {
|
|
140
|
-
var field =
|
|
140
|
+
var field = attr.column ? attr.column : k;
|
|
141
141
|
var x = void 0;
|
|
142
142
|
if (v == null) {
|
|
143
|
-
x =
|
|
143
|
+
x = "null";
|
|
144
144
|
}
|
|
145
|
-
else if (v ===
|
|
145
|
+
else if (v === "") {
|
|
146
146
|
x = "''";
|
|
147
147
|
}
|
|
148
|
-
else if (typeof v ===
|
|
148
|
+
else if (typeof v === "number") {
|
|
149
149
|
x = toString(v);
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
152
|
x = buildParam(i++);
|
|
153
|
-
if (typeof v ===
|
|
153
|
+
if (typeof v === "boolean") {
|
|
154
154
|
if (v === true) {
|
|
155
|
-
var v2 =
|
|
155
|
+
var v2 = attr.true ? "" + attr.true : "'1'";
|
|
156
156
|
args.push(v2);
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
159
|
-
var v2 =
|
|
159
|
+
var v2 = attr.false ? "" + attr.false : "'0'";
|
|
160
160
|
args.push(v2);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -169,11 +169,11 @@ function buildToSave(obj, table, attrs, ver, buildParam, i) {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
if (colSet.length === 0) {
|
|
172
|
-
var q = "insert ignore into " + table + "(" + cols.join(
|
|
172
|
+
var q = "insert ignore into " + table + "(" + cols.join(",") + ")values(" + values.join(",") + ")";
|
|
173
173
|
return { query: q, params: args };
|
|
174
174
|
}
|
|
175
175
|
else {
|
|
176
|
-
var q = "insert into " + table + "(" + cols.join(
|
|
176
|
+
var q = "insert into " + table + "(" + cols.join(",") + ")values(" + values.join(",") + ") on duplicate key update " + colSet.join(",");
|
|
177
177
|
return { query: q, params: args };
|
|
178
178
|
}
|
|
179
179
|
}
|
|
@@ -201,29 +201,29 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
201
201
|
v = attr.default;
|
|
202
202
|
}
|
|
203
203
|
if (v != null && v !== undefined && !attr.ignored && !attr.noinsert) {
|
|
204
|
-
var field =
|
|
204
|
+
var field = attr.column ? attr.column : k;
|
|
205
205
|
cols.push(field);
|
|
206
206
|
if (k === ver) {
|
|
207
207
|
isVersion = true;
|
|
208
208
|
values.push("" + 1);
|
|
209
209
|
}
|
|
210
210
|
else {
|
|
211
|
-
if (v ===
|
|
211
|
+
if (v === "") {
|
|
212
212
|
values.push("''");
|
|
213
213
|
}
|
|
214
|
-
else if (typeof v ===
|
|
214
|
+
else if (typeof v === "number") {
|
|
215
215
|
values.push(toString(v));
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
218
218
|
var p = buildParam(i++);
|
|
219
219
|
values.push(p);
|
|
220
|
-
if (typeof v ===
|
|
220
|
+
if (typeof v === "boolean") {
|
|
221
221
|
if (v === true) {
|
|
222
|
-
var v2 =
|
|
222
|
+
var v2 = attr.true ? attr.true : "'1'";
|
|
223
223
|
args.push(v2);
|
|
224
224
|
}
|
|
225
225
|
else {
|
|
226
|
-
var v2 =
|
|
226
|
+
var v2 = attr.false ? attr.false : "'0'";
|
|
227
227
|
args.push(v2);
|
|
228
228
|
}
|
|
229
229
|
}
|
|
@@ -236,7 +236,7 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
236
236
|
}
|
|
237
237
|
if (!isVersion && ver && ver.length > 0) {
|
|
238
238
|
var attr = attrs[ver];
|
|
239
|
-
var field =
|
|
239
|
+
var field = attr.column ? attr.column : ver;
|
|
240
240
|
cols.push(field);
|
|
241
241
|
values.push("" + 1);
|
|
242
242
|
}
|
|
@@ -247,26 +247,26 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
247
247
|
if (v !== undefined) {
|
|
248
248
|
var attr = attrs[k];
|
|
249
249
|
if (attr && !attr.key && !attr.ignored && k !== ver && !attr.noupdate) {
|
|
250
|
-
var field =
|
|
250
|
+
var field = attr.column ? attr.column : k;
|
|
251
251
|
var x = void 0;
|
|
252
252
|
if (v == null) {
|
|
253
|
-
x =
|
|
253
|
+
x = "null";
|
|
254
254
|
}
|
|
255
|
-
else if (v ===
|
|
255
|
+
else if (v === "") {
|
|
256
256
|
x = "''";
|
|
257
257
|
}
|
|
258
|
-
else if (typeof v ===
|
|
258
|
+
else if (typeof v === "number") {
|
|
259
259
|
x = toString(v);
|
|
260
260
|
}
|
|
261
261
|
else {
|
|
262
262
|
x = buildParam(i++);
|
|
263
|
-
if (typeof v ===
|
|
263
|
+
if (typeof v === "boolean") {
|
|
264
264
|
if (v === true) {
|
|
265
|
-
var v2 =
|
|
265
|
+
var v2 = attr.true ? "" + attr.true : "'1'";
|
|
266
266
|
args.push(v2);
|
|
267
267
|
}
|
|
268
268
|
else {
|
|
269
|
-
var v2 =
|
|
269
|
+
var v2 = attr.false ? "" + attr.false : "'0'";
|
|
270
270
|
args.push(v2);
|
|
271
271
|
}
|
|
272
272
|
}
|
|
@@ -279,12 +279,12 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
if (colSet.length === 0) {
|
|
282
|
-
var q = "insert ignore into " + table + "(" + cols.join(
|
|
282
|
+
var q = "insert ignore into " + table + "(" + cols.join(",") + ")values(" + values.join(",") + ");";
|
|
283
283
|
var smt = { query: q, params: args };
|
|
284
284
|
sts.push(smt);
|
|
285
285
|
}
|
|
286
286
|
else {
|
|
287
|
-
var q = "insert into " + table + "(" + cols.join(
|
|
287
|
+
var q = "insert into " + table + "(" + cols.join(",") + ")values(" + values.join(",") + ") on duplicate key update " + colSet.join(",") + ";";
|
|
288
288
|
var smt = { query: q, params: args };
|
|
289
289
|
sts.push(smt);
|
|
290
290
|
}
|
|
@@ -292,11 +292,11 @@ function buildToSaveBatch(objs, table, attrs, ver, buildParam) {
|
|
|
292
292
|
return sts;
|
|
293
293
|
}
|
|
294
294
|
exports.buildToSaveBatch = buildToSaveBatch;
|
|
295
|
-
var n =
|
|
295
|
+
var n = "NaN";
|
|
296
296
|
function toString(v) {
|
|
297
|
-
var x =
|
|
297
|
+
var x = "" + v;
|
|
298
298
|
if (x === n) {
|
|
299
|
-
x =
|
|
299
|
+
x = "null";
|
|
300
300
|
}
|
|
301
301
|
return x;
|
|
302
302
|
}
|