query-core 0.1.16 → 0.1.17
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/package.json +1 -1
- package/src/services.ts +4 -4
package/package.json
CHANGED
package/src/services.ts
CHANGED
|
@@ -13,7 +13,7 @@ export class SqlLoader<T, ID> {
|
|
|
13
13
|
attributes: Attributes;
|
|
14
14
|
bools?: Attribute[];
|
|
15
15
|
constructor(public table: string,
|
|
16
|
-
public query: (sql: string, args?: any[], m?: StringMap, bools?: Attribute[], ctx?: any) => Promise<
|
|
16
|
+
public query: <K>(sql: string, args?: any[], m?: StringMap, bools?: Attribute[], ctx?: any) => Promise<K[]>,
|
|
17
17
|
attrs: Attributes|string[],
|
|
18
18
|
public param: (i: number) => string,
|
|
19
19
|
public fromDB?: (v: T) => T) {
|
|
@@ -48,7 +48,7 @@ export class SqlLoader<T, ID> {
|
|
|
48
48
|
}
|
|
49
49
|
const fn = this.fromDB;
|
|
50
50
|
if (fn) {
|
|
51
|
-
return this.query(stmt.query, stmt.params, this.map, ctx).then(res => {
|
|
51
|
+
return this.query<T>(stmt.query, stmt.params, this.map, ctx).then(res => {
|
|
52
52
|
if (!res || res.length === 0) {
|
|
53
53
|
return null;
|
|
54
54
|
} else {
|
|
@@ -57,7 +57,7 @@ export class SqlLoader<T, ID> {
|
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
} else {
|
|
60
|
-
return this.query(stmt.query, stmt.params, this.map).then(res => (!res || res.length === 0) ? null : res[0]);
|
|
60
|
+
return this.query<T>(stmt.query, stmt.params, this.map).then(res => (!res || res.length === 0) ? null : res[0]);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
exist(id: ID, ctx?: any): Promise<boolean> {
|
|
@@ -73,7 +73,7 @@ export class SqlSearchLoader<T, ID, S extends Filter> extends SqlLoader<T, ID> {
|
|
|
73
73
|
constructor(
|
|
74
74
|
protected find: (s: S, limit?: number, offset?: number|string, fields?: string[]) => Promise<SearchResult<T>>,
|
|
75
75
|
table: string,
|
|
76
|
-
query: (sql: string, args?: any[], m?: StringMap, bools?: Attribute[], ctx?: any) => Promise<
|
|
76
|
+
query: <K>(sql: string, args?: any[], m?: StringMap, bools?: Attribute[], ctx?: any) => Promise<K[]>,
|
|
77
77
|
attrs: Attributes|string[],
|
|
78
78
|
param: (i: number) => string,
|
|
79
79
|
fromDB?: (v: T) => T) {
|