speed 1.1.3 → 1.1.8
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 +17 -3
- package/index.js +14 -5
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/speed.decorator.js +54 -153
- package/speed.decorator.js.map +1 -1
- package/speed.decorator.ts +9 -3
- package/speed.service.js +19 -11
- package/speed.service.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## SpeedSQL
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/speed)
|
|
4
|
+
[](https://www.npmjs.com/package/speed)
|
|
5
|
+
[](https://www.npmjs.com/package/speed)
|
|
6
|
+
[](https://www.npmjs.com/package/speed)
|
|
7
|
+
[](https://github.com/SpeedPHP/speedsql/blob/main/LICENSE)
|
|
8
|
+
|
|
3
9
|
SQL injection for NestJS, similar mybatis.
|
|
4
10
|
|
|
5
11
|
### Introduction
|
|
@@ -11,6 +17,10 @@ SQL injection for NestJS, similar mybatis.
|
|
|
11
17
|
- Support for Entity Injection.
|
|
12
18
|
- Support the Connection pools by mysql2 within.
|
|
13
19
|
|
|
20
|
+
### Support Decorators
|
|
21
|
+
|
|
22
|
+
`@Param`, `@ResultType`, `@Select`, `@Insert`, `@Update`, `@Delete`.
|
|
23
|
+
|
|
14
24
|
### Install as a dependency
|
|
15
25
|
|
|
16
26
|
Setup SpeedSQL (NPM named `speed`) as dependency in *package.json* file `dependencies`
|
|
@@ -186,6 +196,8 @@ export class AppModule {}
|
|
|
186
196
|
|
|
187
197
|
### Parameter with named (for Prepared Statements)
|
|
188
198
|
|
|
199
|
+
`@Param` define the named parameters.
|
|
200
|
+
|
|
189
201
|
As with MyBatis, SpeedSQL is possible to pass a value to a bind parameter as a named parameter to ensure readability and prevent SQL Injection attacks.
|
|
190
202
|
|
|
191
203
|
Unlike [Prepared Statements](https://github.com/sidorares/node-mysql2#using-prepared-statements) in mysql2, SpeedSQL can be pass param value with named to make SQL more clearer.
|
|
@@ -241,10 +253,12 @@ So we can start to use.
|
|
|
241
253
|
const users: UserDto[] = await this.appService.getRecords('zzz', 10);
|
|
242
254
|
```
|
|
243
255
|
|
|
244
|
-
### Select
|
|
256
|
+
### @Select
|
|
245
257
|
|
|
246
258
|
SpeedSQL uses ```@ResultType``` to annotate the resulting entity.
|
|
247
259
|
|
|
260
|
+
`@ResultType` define the data entity for @Selete returns.
|
|
261
|
+
|
|
248
262
|
Select returns an array of annotated entity (```@ResultType```).
|
|
249
263
|
|
|
250
264
|
- Create a entity:
|
|
@@ -277,7 +291,7 @@ getRecords(@Param('uid') uid:number, @Param('name') name:string): UserDto[] {ret
|
|
|
277
291
|
```
|
|
278
292
|
|
|
279
293
|
|
|
280
|
-
### Insert
|
|
294
|
+
### @Insert
|
|
281
295
|
|
|
282
296
|
Parameter with named is also supported in ```@Insert```.
|
|
283
297
|
|
|
@@ -290,7 +304,7 @@ import { Insert } from 'speed';
|
|
|
290
304
|
addUser(user: UserDto): number {return;}
|
|
291
305
|
```
|
|
292
306
|
|
|
293
|
-
### Update and Delete
|
|
307
|
+
### @Update and @Delete
|
|
294
308
|
|
|
295
309
|
Parameter with named is also supported in ```@Update``` and ```@Delete```.
|
|
296
310
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./speed.decorator"), exports);
|
|
14
|
+
__exportStar(require("./speed.service"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAAgC"}
|
package/package.json
CHANGED
package/speed.decorator.js
CHANGED
|
@@ -1,57 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
12
|
-
return { next: verb(0), "throw": verb(1), "return": verb(2) };
|
|
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 (_) try {
|
|
17
|
-
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [0, 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
|
-
};
|
|
37
|
-
var speed_service_1 = require("./speed.service");
|
|
38
|
-
var paramMetadataKey = Symbol('param');
|
|
39
|
-
function log(message) {
|
|
40
|
-
var optionalParams = [];
|
|
41
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
42
|
-
optionalParams[_i - 1] = arguments[_i];
|
|
43
|
-
}
|
|
44
|
-
console.log.apply(console, [message].concat(optionalParams));
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Delete = exports.Update = exports.Insert = exports.Select = exports.ResultType = exports.Param = exports.log = void 0;
|
|
4
|
+
const speed_service_1 = require("./speed.service");
|
|
5
|
+
const paramMetadataKey = Symbol('param');
|
|
6
|
+
function log(message, ...optionalParams) {
|
|
7
|
+
console.log(message, ...optionalParams);
|
|
45
8
|
}
|
|
46
9
|
exports.log = log;
|
|
47
10
|
function ResultType(constructorFunction) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
args[_i] = arguments[_i];
|
|
52
|
-
}
|
|
53
|
-
var func = function () {
|
|
54
|
-
return new (constructorFunction.bind.apply(constructorFunction, [void 0].concat(args)))();
|
|
11
|
+
const newConstructorFunction = function (...args) {
|
|
12
|
+
const func = function () {
|
|
13
|
+
return new constructorFunction(...args);
|
|
55
14
|
};
|
|
56
15
|
func.prototype = constructorFunction.prototype;
|
|
57
16
|
return new func();
|
|
@@ -59,103 +18,62 @@ function ResultType(constructorFunction) {
|
|
|
59
18
|
newConstructorFunction.prototype = constructorFunction.prototype;
|
|
60
19
|
return function (target, propertyKey) {
|
|
61
20
|
speed_service_1.resultTypeMap.set([target.constructor.name, propertyKey].toString(), newConstructorFunction());
|
|
62
|
-
//never return
|
|
63
21
|
};
|
|
64
22
|
}
|
|
65
23
|
exports.ResultType = ResultType;
|
|
66
24
|
function Param(name) {
|
|
67
25
|
return function (target, propertyKey, parameterIndex) {
|
|
68
|
-
|
|
26
|
+
const existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey) || [];
|
|
69
27
|
existingParameters.push([name, parameterIndex]);
|
|
70
28
|
Reflect.defineMetadata(paramMetadataKey, existingParameters, target, propertyKey);
|
|
71
29
|
};
|
|
72
30
|
}
|
|
73
31
|
exports.Param = Param;
|
|
74
32
|
function convertSQLParams(args, target, propertyKey, decoratorSQL) {
|
|
75
|
-
|
|
76
|
-
|
|
33
|
+
const queryValues = [];
|
|
34
|
+
let argsVal;
|
|
77
35
|
if (typeof args[0] === 'object') {
|
|
78
|
-
argsVal = new Map(Object.getOwnPropertyNames(args[0]).map(
|
|
36
|
+
argsVal = new Map(Object.getOwnPropertyNames(args[0]).map((valName) => [
|
|
79
37
|
valName,
|
|
80
38
|
args[0][valName],
|
|
81
|
-
]
|
|
39
|
+
]));
|
|
82
40
|
}
|
|
83
41
|
else {
|
|
84
|
-
|
|
85
|
-
argsVal = new Map(existingParameters.map(
|
|
86
|
-
var argName = _a[0], argIdx = _a[1];
|
|
87
|
-
return [argName, args[argIdx]];
|
|
88
|
-
}));
|
|
42
|
+
const existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey);
|
|
43
|
+
argsVal = new Map(existingParameters.map(([argName, argIdx]) => [argName, args[argIdx]]));
|
|
89
44
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
45
|
+
const regExp = /#{(\w+)}/;
|
|
46
|
+
let match;
|
|
47
|
+
while (match = regExp.exec(decoratorSQL)) {
|
|
48
|
+
const [replaceTag, matchName] = match;
|
|
93
49
|
decoratorSQL = decoratorSQL.replace(new RegExp(replaceTag, 'g'), '?');
|
|
94
50
|
queryValues.push(argsVal.get(matchName));
|
|
95
|
-
}
|
|
51
|
+
}
|
|
96
52
|
return [decoratorSQL, queryValues];
|
|
97
53
|
}
|
|
98
|
-
function queryForExecute(sql, args, target, propertyKey) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (args.length > 0) {
|
|
107
|
-
_a = convertSQLParams(args, target, propertyKey, sql), newSql = _a[0], sqlValues = _a[1];
|
|
108
|
-
}
|
|
109
|
-
return [4 /*yield*/, speed_service_1.speedPromisePool.query(newSql, sqlValues)];
|
|
110
|
-
case 1:
|
|
111
|
-
result = (_b.sent())[0];
|
|
112
|
-
return [2 /*return*/, result];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
54
|
+
async function queryForExecute(sql, args, target, propertyKey) {
|
|
55
|
+
let sqlValues = [];
|
|
56
|
+
let newSql = sql;
|
|
57
|
+
if (args.length > 0) {
|
|
58
|
+
[newSql, sqlValues] = convertSQLParams(args, target, propertyKey, sql);
|
|
59
|
+
}
|
|
60
|
+
const [result] = await speed_service_1.speedPromisePool.query(newSql, sqlValues);
|
|
61
|
+
return result;
|
|
116
62
|
}
|
|
117
63
|
function Insert(sql) {
|
|
118
64
|
return function (target, propertyKey, descriptor) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
123
|
-
args[_i] = arguments[_i];
|
|
124
|
-
}
|
|
125
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
126
|
-
var result;
|
|
127
|
-
return __generator(this, function (_a) {
|
|
128
|
-
switch (_a.label) {
|
|
129
|
-
case 0: return [4 /*yield*/, queryForExecute(sql, args, target, propertyKey)];
|
|
130
|
-
case 1:
|
|
131
|
-
result = _a.sent();
|
|
132
|
-
return [2 /*return*/, result.insertId];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
});
|
|
65
|
+
descriptor.value = async (...args) => {
|
|
66
|
+
const result = await queryForExecute(sql, args, target, propertyKey);
|
|
67
|
+
return result.insertId;
|
|
136
68
|
};
|
|
137
69
|
};
|
|
138
70
|
}
|
|
139
71
|
exports.Insert = Insert;
|
|
140
72
|
function Update(sql) {
|
|
141
73
|
return function (target, propertyKey, descriptor) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
146
|
-
args[_i] = arguments[_i];
|
|
147
|
-
}
|
|
148
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
149
|
-
var result;
|
|
150
|
-
return __generator(this, function (_a) {
|
|
151
|
-
switch (_a.label) {
|
|
152
|
-
case 0: return [4 /*yield*/, queryForExecute(sql, args, target, propertyKey)];
|
|
153
|
-
case 1:
|
|
154
|
-
result = _a.sent();
|
|
155
|
-
return [2 /*return*/, result.affectedRows];
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
});
|
|
74
|
+
descriptor.value = async (...args) => {
|
|
75
|
+
const result = await queryForExecute(sql, args, target, propertyKey);
|
|
76
|
+
return result.affectedRows;
|
|
159
77
|
};
|
|
160
78
|
};
|
|
161
79
|
}
|
|
@@ -163,46 +81,29 @@ exports.Update = Update;
|
|
|
163
81
|
exports.Delete = Update;
|
|
164
82
|
function Select(sql) {
|
|
165
83
|
return function (target, propertyKey, descriptor) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
84
|
+
descriptor.value = async (...args) => {
|
|
85
|
+
let sqlValues = [];
|
|
86
|
+
if (args.length > 0) {
|
|
87
|
+
[sql, sqlValues] = convertSQLParams(args, target, propertyKey, sql);
|
|
88
|
+
}
|
|
89
|
+
const [rows] = await speed_service_1.speedPromisePool.query(sql, sqlValues);
|
|
90
|
+
if (Object.keys(rows).length === 0) {
|
|
91
|
+
return;
|
|
171
92
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
_a = convertSQLParams(args, target, propertyKey, sql), sql = _a[0], sqlValues = _a[1];
|
|
180
|
-
}
|
|
181
|
-
return [4 /*yield*/, speed_service_1.speedPromisePool.query(sql, sqlValues)];
|
|
182
|
-
case 1:
|
|
183
|
-
rows = (_b.sent())[0];
|
|
184
|
-
if (Object.keys(rows).length === 0) {
|
|
185
|
-
return [2 /*return*/];
|
|
186
|
-
}
|
|
187
|
-
records = [];
|
|
188
|
-
resultType = speed_service_1.resultTypeMap.get([target.constructor.name, propertyKey].toString());
|
|
189
|
-
_loop_1 = function (rowIndex) {
|
|
190
|
-
var entity = Object.create(resultType);
|
|
191
|
-
Object.getOwnPropertyNames(resultType).forEach(function (propertyRow) {
|
|
192
|
-
if (rows[rowIndex].hasOwnProperty(propertyRow)) {
|
|
193
|
-
Object.defineProperty(entity, propertyRow, Object.getOwnPropertyDescriptor(rows[rowIndex], propertyRow));
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
records.push(entity);
|
|
197
|
-
};
|
|
198
|
-
for (rowIndex in rows) {
|
|
199
|
-
_loop_1(rowIndex);
|
|
200
|
-
}
|
|
201
|
-
return [2 /*return*/, records];
|
|
93
|
+
const records = [];
|
|
94
|
+
const resultType = speed_service_1.resultTypeMap.get([target.constructor.name, propertyKey].toString());
|
|
95
|
+
for (const rowIndex in rows) {
|
|
96
|
+
const entity = Object.create(resultType);
|
|
97
|
+
Object.getOwnPropertyNames(resultType).forEach(function (propertyRow) {
|
|
98
|
+
if (rows[rowIndex].hasOwnProperty(propertyRow)) {
|
|
99
|
+
Object.defineProperty(entity, propertyRow, Object.getOwnPropertyDescriptor(rows[rowIndex], propertyRow));
|
|
202
100
|
}
|
|
203
101
|
});
|
|
204
|
-
|
|
102
|
+
records.push(entity);
|
|
103
|
+
}
|
|
104
|
+
return records;
|
|
205
105
|
};
|
|
206
106
|
};
|
|
207
107
|
}
|
|
208
108
|
exports.Select = Select;
|
|
109
|
+
//# sourceMappingURL=speed.decorator.js.map
|
package/speed.decorator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speed.decorator.js","sourceRoot":"","sources":["speed.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"speed.decorator.js","sourceRoot":"","sources":["speed.decorator.ts"],"names":[],"mappings":";;;AAAA,mDAAkE;AAGlE,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAEzC,SAAS,GAAG,CAAC,OAAa,EAAE,GAAG,cAAqB;IAClD,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC,CAAC;AAC1C,CAAC;AAsKQ,kBAAG;AApKZ,SAAS,UAAU,CAAC,mBAAmB;IACrC,MAAM,sBAAsB,GAAQ,UAAU,GAAG,IAAI;QACnD,MAAM,IAAI,GAAQ;YAChB,OAAO,IAAI,mBAAmB,CAAC,GAAG,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC;QAC/C,OAAO,IAAI,IAAI,EAAE,CAAC;IACpB,CAAC,CAAC;IACF,sBAAsB,CAAC,SAAS,GAAG,mBAAmB,CAAC,SAAS,CAAC;IACjE,OAAO,UAAU,MAAM,EAAE,WAAmB;QAC1C,6BAAa,CAAC,GAAG,CACb,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAA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C,QAAQ,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE;wBAC9C,MAAM,CAAC,cAAc,CACjB,MAAM,EACN,WAAW,EACX,MAAM,CAAC,wBAAwB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,CAC/D,CAAC;qBACH;gBACH,CAAC,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACtB;YACD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAEgC,wBAAM"}
|
package/speed.decorator.ts
CHANGED
|
@@ -68,12 +68,18 @@ function convertSQLParams(
|
|
|
68
68
|
existingParameters.map(([argName, argIdx]) => [argName, args[argIdx]]),
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
|
-
const regExp = /#{(\w+)}
|
|
72
|
-
|
|
71
|
+
const regExp = /#{(\w+)}/;
|
|
72
|
+
let match;
|
|
73
|
+
while(match = regExp.exec(decoratorSQL)){
|
|
73
74
|
const [replaceTag, matchName] = match;
|
|
74
75
|
decoratorSQL = decoratorSQL.replace(new RegExp(replaceTag, 'g'), '?');
|
|
75
76
|
queryValues.push(argsVal.get(matchName));
|
|
76
|
-
}
|
|
77
|
+
}
|
|
78
|
+
// [...decoratorSQL.matchAll(regExp)].forEach((match) => {
|
|
79
|
+
// const [replaceTag, matchName] = match;
|
|
80
|
+
// decoratorSQL = decoratorSQL.replace(new RegExp(replaceTag, 'g'), '?');
|
|
81
|
+
// queryValues.push(argsVal.get(matchName));
|
|
82
|
+
// });
|
|
77
83
|
return [decoratorSQL, queryValues];
|
|
78
84
|
}
|
|
79
85
|
|
package/speed.service.js
CHANGED
|
@@ -5,25 +5,33 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
13
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
exports.createPool =
|
|
14
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.Pool = exports.createPool = exports.resultTypeMap = exports.speedPromisePool = exports.SpeedService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const mysql2_1 = require("mysql2");
|
|
19
|
+
Object.defineProperty(exports, "Pool", { enumerable: true, get: function () { return mysql2_1.Pool; } });
|
|
20
|
+
Object.defineProperty(exports, "createPool", { enumerable: true, get: function () { return mysql2_1.createPool; } });
|
|
21
|
+
let speedPromisePool;
|
|
15
22
|
exports.speedPromisePool = speedPromisePool;
|
|
16
|
-
|
|
23
|
+
const resultTypeMap = new Map();
|
|
17
24
|
exports.resultTypeMap = resultTypeMap;
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
let SpeedService = class SpeedService {
|
|
26
|
+
constructor(pool) {
|
|
20
27
|
this.pool = pool;
|
|
21
28
|
exports.speedPromisePool = speedPromisePool = pool.promise();
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
}());
|
|
30
|
+
};
|
|
25
31
|
SpeedService = __decorate([
|
|
26
|
-
common_1.Injectable(),
|
|
27
|
-
__param(0, common_1.Inject('SPEED_POOL'))
|
|
32
|
+
(0, common_1.Injectable)(),
|
|
33
|
+
__param(0, (0, common_1.Inject)('SPEED_POOL')),
|
|
34
|
+
__metadata("design:paramtypes", [typeof (_a = typeof mysql2_1.Pool !== "undefined" && mysql2_1.Pool) === "function" ? _a : Object])
|
|
28
35
|
], SpeedService);
|
|
29
36
|
exports.SpeedService = SpeedService;
|
|
37
|
+
//# sourceMappingURL=speed.service.js.map
|
package/speed.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speed.service.js","sourceRoot":"","sources":["speed.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"speed.service.js","sourceRoot":"","sources":["speed.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,mCAA0C;AAYY,qFAZ7C,aAAI,OAY6C;AAAhB,2FAZ3B,mBAAU,OAY2B;AATpD,IAAI,gBAA6B,CAAC;AASzB,4CAAgB;AARzB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAe,CAAC;AAQlB,sCAAa;AALxC,IAAa,YAAY,GAAzB,MAAa,YAAY;IACrB,YAA0C,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;QAChD,2BAAA,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IACtC,CAAC;CACJ,CAAA;AAJY,YAAY;IADxB,IAAA,mBAAU,GAAE;IAEI,WAAA,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;yDAAe,aAAI,oBAAJ,aAAI;GAD3C,YAAY,CAIxB;AAJY,oCAAY"}
|