badmfck-api-server 1.9.7 → 1.9.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -24,7 +24,7 @@ export interface MysqlResult {
|
|
24
24
|
}
|
25
25
|
export interface MySqlQuery {
|
26
26
|
query: string;
|
27
|
-
fields: MysqlQueryField[];
|
27
|
+
fields: MysqlQueryField[] | MysqlQueryFieldObject;
|
28
28
|
}
|
29
29
|
export interface MysqlQueryField {
|
30
30
|
name: string;
|
@@ -35,6 +35,14 @@ export interface MysqlQueryField {
|
|
35
35
|
useInReplace?: boolean;
|
36
36
|
_parsedValue?: string | number | boolean | null;
|
37
37
|
}
|
38
|
+
export interface MysqlQueryFieldObject extends Record<string, string | number | boolean | null | undefined | {
|
39
|
+
value: string | number | boolean | null | undefined;
|
40
|
+
system?: boolean;
|
41
|
+
ignoreInInsert?: boolean;
|
42
|
+
ignoreInUpdate?: boolean;
|
43
|
+
useInReplace?: boolean;
|
44
|
+
}> {
|
45
|
+
}
|
38
46
|
export declare class MysqlService extends BaseService {
|
39
47
|
reconnectionTimeout: number;
|
40
48
|
reconnecting: boolean;
|
@@ -48,7 +56,9 @@ export declare class MysqlService extends BaseService {
|
|
48
56
|
init(): Promise<void>;
|
49
57
|
recreatePool(): Promise<void>;
|
50
58
|
onApplicationReady(): Promise<void>;
|
51
|
-
static
|
59
|
+
static fieldsToObject(fields: MysqlQueryField[] | MysqlQueryFieldObject): MysqlQueryFieldObject;
|
60
|
+
static objectToFields(obj: MysqlQueryFieldObject | MysqlQueryField[]): MysqlQueryField[];
|
61
|
+
static prepareQuery(query: string, fields: MysqlQueryField[] | MysqlQueryFieldObject): string;
|
52
62
|
static prepareQueryFieldValue(value: string | number | boolean | null | undefined, system?: boolean): string | number | boolean | null | undefined;
|
53
63
|
execute(query: string): Promise<MysqlResult>;
|
54
64
|
sendQuery(conn: PoolConnection, query: string, resolve: (data: MysqlResult) => void): void;
|
@@ -88,7 +88,55 @@ class MysqlService extends BaseService_1.BaseService {
|
|
88
88
|
}
|
89
89
|
}
|
90
90
|
async onApplicationReady() { }
|
91
|
+
static fieldsToObject(fields) {
|
92
|
+
if (!Array.isArray(fields))
|
93
|
+
return fields;
|
94
|
+
const obj = {};
|
95
|
+
for (let i of fields) {
|
96
|
+
if (!i.name)
|
97
|
+
continue;
|
98
|
+
if (typeof i.value !== "object")
|
99
|
+
obj[i.name] = i.value;
|
100
|
+
else {
|
101
|
+
obj[i.name] = {
|
102
|
+
value: i.value,
|
103
|
+
system: i.system,
|
104
|
+
ignoreInInsert: i.ignoreInInsert,
|
105
|
+
ignoreInUpdate: i.ignoreInUpdate,
|
106
|
+
useInReplace: i.useInReplace
|
107
|
+
};
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return obj;
|
111
|
+
}
|
112
|
+
static objectToFields(obj) {
|
113
|
+
if (Array.isArray(obj))
|
114
|
+
return obj;
|
115
|
+
const fields = [];
|
116
|
+
for (let i in obj) {
|
117
|
+
if (typeof obj[i] === "object") {
|
118
|
+
const mo = obj[i];
|
119
|
+
fields.push({
|
120
|
+
name: i,
|
121
|
+
value: mo.value,
|
122
|
+
system: mo.system,
|
123
|
+
ignoreInInsert: mo.system,
|
124
|
+
ignoreInUpdate: mo.system,
|
125
|
+
useInReplace: mo.system
|
126
|
+
});
|
127
|
+
}
|
128
|
+
else {
|
129
|
+
fields.push({
|
130
|
+
name: i,
|
131
|
+
value: obj[i]
|
132
|
+
});
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return fields;
|
136
|
+
}
|
91
137
|
static prepareQuery(query, fields) {
|
138
|
+
if (!Array.isArray(fields))
|
139
|
+
fields = MysqlService.objectToFields(fields);
|
92
140
|
for (let i of fields) {
|
93
141
|
const val = this.prepareQueryFieldValue(i.value, i.system);
|
94
142
|
i._parsedValue = val;
|