@asla/yoursql 0.6.1 → 0.6.2
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/dist/mod.js +8 -10
- package/dist/sql_value/sql_value.d.ts +1 -1
- package/package.json +1 -1
package/dist/mod.js
CHANGED
|
@@ -284,7 +284,7 @@ class SqlQueryStatement extends SqlSelectable {
|
|
|
284
284
|
}
|
|
285
285
|
_SqlQueryStatement_sql = new WeakMap();
|
|
286
286
|
|
|
287
|
-
var
|
|
287
|
+
var _YourValuesAs_asName, _YourValuesAs_valuesStr, _YourValuesAs_sql;
|
|
288
288
|
/**
|
|
289
289
|
* SQL 原始字符类。可以使用 String 类代替,这只是为了推断类型
|
|
290
290
|
* @public
|
|
@@ -313,20 +313,19 @@ class SqlValuesCreator {
|
|
|
313
313
|
* @param map - 自定义对象转换
|
|
314
314
|
*/
|
|
315
315
|
constructor(map) {
|
|
316
|
-
|
|
317
|
-
__classPrivateFieldSet(this, _SqlValuesCreator_map, new Map(map), "f");
|
|
316
|
+
this._map = new Map(map);
|
|
318
317
|
}
|
|
319
318
|
setTransformer(type_map, encoder) {
|
|
320
319
|
if (typeof type_map === "function") {
|
|
321
320
|
if (encoder)
|
|
322
|
-
|
|
321
|
+
this._map.set(type_map, encoder);
|
|
323
322
|
else
|
|
324
|
-
|
|
323
|
+
this._map.delete(type_map);
|
|
325
324
|
}
|
|
326
325
|
else {
|
|
327
326
|
for (const [type, encoder] of type_map) {
|
|
328
327
|
if (typeof type === "function" && typeof encoder === "function") {
|
|
329
|
-
|
|
328
|
+
this._map.set(type, encoder);
|
|
330
329
|
}
|
|
331
330
|
}
|
|
332
331
|
}
|
|
@@ -342,7 +341,7 @@ class SqlValuesCreator {
|
|
|
342
341
|
let basicType;
|
|
343
342
|
if (assertType) {
|
|
344
343
|
if (typeof assertType === "function") {
|
|
345
|
-
let type =
|
|
344
|
+
let type = this._map.get(assertType);
|
|
346
345
|
if (!type)
|
|
347
346
|
throw new Error("类型不存在");
|
|
348
347
|
return type.call(this, value);
|
|
@@ -379,9 +378,9 @@ class SqlValuesCreator {
|
|
|
379
378
|
}
|
|
380
379
|
/** 获取值对应的 SqlValueEncoder */
|
|
381
380
|
getObjectType(value) {
|
|
382
|
-
for (const Class of
|
|
381
|
+
for (const Class of this._map.keys()) {
|
|
383
382
|
if (value instanceof Class)
|
|
384
|
-
return
|
|
383
|
+
return this._map.get(Class);
|
|
385
384
|
}
|
|
386
385
|
return this.defaultObject;
|
|
387
386
|
}
|
|
@@ -499,7 +498,6 @@ class SqlValuesCreator {
|
|
|
499
498
|
return new YourValuesAs(insertKeys, asName, valuesStr.join(",\n"));
|
|
500
499
|
}
|
|
501
500
|
}
|
|
502
|
-
_SqlValuesCreator_map = new WeakMap();
|
|
503
501
|
class YourValuesAs extends SqlSelectable {
|
|
504
502
|
constructor(columns, asName, valuesStr) {
|
|
505
503
|
super();
|
|
@@ -27,7 +27,6 @@ export type SqlValueFn = SqlValuesCreator & {
|
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
29
|
export declare class SqlValuesCreator {
|
|
30
|
-
#private;
|
|
31
30
|
static create(map?: JsObjectMapSql): SqlValueFn;
|
|
32
31
|
/**
|
|
33
32
|
* 将字符串转为 SQL 的字符串值的形式(单引号会被转义)。
|
|
@@ -41,6 +40,7 @@ export declare class SqlValuesCreator {
|
|
|
41
40
|
/** 设置转换器 */
|
|
42
41
|
setTransformer(type: new (...args: any[]) => any, encoder?: SqlValueEncoder): void;
|
|
43
42
|
setTransformer(map: JsObjectMapSql): void;
|
|
43
|
+
private readonly _map;
|
|
44
44
|
/**
|
|
45
45
|
* 将 JS 对象转为 SQL 的字符值的形式 。 undefined 将被转换为 DEFAULT
|
|
46
46
|
* ```ts
|