badmfck-api-server 1.9.7 → 1.9.8

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 prepareQuery(query: string, fields: MysqlQueryField[]): string;
59
+ static fieldsToObject(fields: MysqlQueryField[]): MysqlQueryFieldObject;
60
+ static objectToFields(obj: MysqlQueryFieldObject): 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,51 @@ class MysqlService extends BaseService_1.BaseService {
88
88
  }
89
89
  }
90
90
  async onApplicationReady() { }
91
+ static fieldsToObject(fields) {
92
+ const obj = {};
93
+ for (let i of fields) {
94
+ if (!i.name)
95
+ continue;
96
+ if (typeof i.value !== "object")
97
+ obj[i.name] = i.value;
98
+ else {
99
+ obj[i.name] = {
100
+ value: i.value,
101
+ system: i.system,
102
+ ignoreInInsert: i.ignoreInInsert,
103
+ ignoreInUpdate: i.ignoreInUpdate,
104
+ useInReplace: i.useInReplace
105
+ };
106
+ }
107
+ }
108
+ return obj;
109
+ }
110
+ static objectToFields(obj) {
111
+ const fields = [];
112
+ for (let i in obj) {
113
+ if (typeof obj[i] === "object") {
114
+ const mo = obj[i];
115
+ fields.push({
116
+ name: i,
117
+ value: mo.value,
118
+ system: mo.system,
119
+ ignoreInInsert: mo.system,
120
+ ignoreInUpdate: mo.system,
121
+ useInReplace: mo.system
122
+ });
123
+ }
124
+ else {
125
+ fields.push({
126
+ name: i,
127
+ value: obj[i]
128
+ });
129
+ }
130
+ }
131
+ return fields;
132
+ }
91
133
  static prepareQuery(query, fields) {
134
+ if (!Array.isArray(fields))
135
+ fields = MysqlService.objectToFields(fields);
92
136
  for (let i of fields) {
93
137
  const val = this.prepareQueryFieldValue(i.value, i.system);
94
138
  i._parsedValue = val;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",