@quillsql/node 0.5.9 → 0.6.0
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/assets/pgtypes.js +1391 -1391
- package/dist/db/BigQuery.js +1 -0
- package/dist/db/CachedConnection.d.ts +3 -1
- package/dist/db/CachedConnection.js +11 -14
- package/dist/db/Postgres.js +28 -21
- package/dist/db/Snowflake.js +2 -2
- package/dist/index.js +14 -5
- package/dist/utils/Error.d.ts +1 -0
- package/dist/utils/Error.js +12 -3
- package/dist/utils/RunQueryProcesses.d.ts +6 -0
- package/eslint.config.mjs +16 -0
- package/examples/mysql-node/app.ts +62 -0
- package/examples/node-server/app.ts +8 -9
- package/package.json +16 -3
- package/src/assets/pgtypes.ts +1392 -1392
- package/src/db/BigQuery.ts +10 -10
- package/src/db/CachedConnection.ts +11 -19
- package/src/db/DatabaseHelper.ts +29 -30
- package/src/db/Mysql.ts +0 -2
- package/src/db/Postgres.ts +38 -40
- package/src/db/Snowflake.ts +14 -15
- package/src/index.ts +20 -6
- package/src/models/Cache.ts +2 -2
- package/src/utils/Error.ts +18 -4
- package/src/utils/RunQueryProcesses.ts +3 -3
- package/src/utils/textProcessing.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import QuillServerClient from "./clients/QuillServerClient";
|
|
2
1
|
import { CacheCredentials } from "./models/Cache";
|
|
3
2
|
import {
|
|
4
3
|
AdditionalProcessing,
|
|
@@ -92,6 +91,11 @@ export class Quill {
|
|
|
92
91
|
}: QuillQueryParams): Promise<QuillQueryResult> {
|
|
93
92
|
this.targetConnection.orgId = orgId;
|
|
94
93
|
let responseMetadata: any = {};
|
|
94
|
+
|
|
95
|
+
if (!metadata.task) {
|
|
96
|
+
return { error: "Missing task.", status: "error", data: {} };
|
|
97
|
+
}
|
|
98
|
+
|
|
95
99
|
try {
|
|
96
100
|
const preQueryResults = metadata.preQueries
|
|
97
101
|
? await this.runQueries(
|
|
@@ -114,7 +118,11 @@ export class Quill {
|
|
|
114
118
|
viewQuery: metadata.preQueries ? metadata.preQueries[0] : undefined,
|
|
115
119
|
});
|
|
116
120
|
if (response.error) {
|
|
117
|
-
return {
|
|
121
|
+
return {
|
|
122
|
+
status: "error",
|
|
123
|
+
error: response.error,
|
|
124
|
+
data: response.metadata || {},
|
|
125
|
+
};
|
|
118
126
|
}
|
|
119
127
|
// if there is no metadata object in the response, create one
|
|
120
128
|
if (response.metadata) {
|
|
@@ -153,8 +161,8 @@ export class Quill {
|
|
|
153
161
|
} catch (err) {
|
|
154
162
|
return {
|
|
155
163
|
status: "error",
|
|
156
|
-
error: (err as any).message,
|
|
157
|
-
data: responseMetadata,
|
|
164
|
+
error: (err as any).response?.data?.error ?? (err as any).message,
|
|
165
|
+
data: responseMetadata || {},
|
|
158
166
|
};
|
|
159
167
|
}
|
|
160
168
|
}
|
|
@@ -177,6 +185,7 @@ export class Quill {
|
|
|
177
185
|
queryResults: [],
|
|
178
186
|
};
|
|
179
187
|
}
|
|
188
|
+
|
|
180
189
|
if (runQueryConfig?.arrayToMap) {
|
|
181
190
|
const mappedArray = await mapQueries(queries, this.targetConnection);
|
|
182
191
|
return { ...results, queryResults: [], mappedArray };
|
|
@@ -221,8 +230,13 @@ export class Quill {
|
|
|
221
230
|
};
|
|
222
231
|
});
|
|
223
232
|
return { ...table, columns: columns, rows: queryResult.rows };
|
|
224
|
-
} catch (err) {
|
|
225
|
-
return {
|
|
233
|
+
} catch (err: any) {
|
|
234
|
+
return {
|
|
235
|
+
...table,
|
|
236
|
+
error: err.message
|
|
237
|
+
? `Error fetching columns: ${err.message}`
|
|
238
|
+
: "Error fetching columns",
|
|
239
|
+
};
|
|
226
240
|
}
|
|
227
241
|
}),
|
|
228
242
|
);
|
package/src/models/Cache.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface Mapable {
|
|
|
4
4
|
key: string,
|
|
5
5
|
value: string,
|
|
6
6
|
type?: string,
|
|
7
|
-
ttl?: number
|
|
7
|
+
ttl?: number,
|
|
8
8
|
): Promise<string | null>;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -15,4 +15,4 @@ export interface CacheCredentials {
|
|
|
15
15
|
port: string;
|
|
16
16
|
cacheType: string;
|
|
17
17
|
ttl?: number;
|
|
18
|
-
}
|
|
18
|
+
}
|
package/src/utils/Error.ts
CHANGED
|
@@ -4,18 +4,32 @@ export class PgError extends Error {
|
|
|
4
4
|
hint?: string;
|
|
5
5
|
position?: string;
|
|
6
6
|
// Add other properties if needed
|
|
7
|
+
constructor(
|
|
8
|
+
message: string,
|
|
9
|
+
detail?: string,
|
|
10
|
+
hint?: string,
|
|
11
|
+
position?: string,
|
|
12
|
+
code?: string,
|
|
13
|
+
) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.detail = detail;
|
|
17
|
+
this.hint = hint;
|
|
18
|
+
this.position = position;
|
|
19
|
+
}
|
|
7
20
|
}
|
|
8
21
|
|
|
9
22
|
export function isSuperset(obj: any, baseClass: any): boolean {
|
|
10
|
-
// Get the property names of the base class
|
|
11
|
-
const
|
|
23
|
+
// Get the property names of the base class instance
|
|
24
|
+
const baseInstance = new baseClass();
|
|
25
|
+
const baseProps = Object.keys(baseInstance);
|
|
12
26
|
|
|
13
27
|
// Check if the object has all the properties of the base class
|
|
14
28
|
for (const prop of baseProps) {
|
|
15
|
-
if (!
|
|
29
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
16
30
|
return false;
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
return true;
|
|
21
|
-
}
|
|
35
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CachedConnection } from "../db/CachedConnection";
|
|
2
2
|
|
|
3
|
-
interface TableSchemaInfo {
|
|
3
|
+
export interface TableSchemaInfo {
|
|
4
4
|
fieldType: string;
|
|
5
5
|
name: string;
|
|
6
6
|
displayName: string;
|
|
@@ -9,7 +9,7 @@ interface TableSchemaInfo {
|
|
|
9
9
|
|
|
10
10
|
export function removeFields(queryResults: any, fieldsToRemove: string[]): any {
|
|
11
11
|
const fields = queryResults.fields.filter(
|
|
12
|
-
(field: { name: any }) => !fieldsToRemove.includes(field.name)
|
|
12
|
+
(field: { name: any }) => !fieldsToRemove.includes(field.name),
|
|
13
13
|
);
|
|
14
14
|
const rows = queryResults.rows.map((row: any) => {
|
|
15
15
|
fieldsToRemove.forEach((field) => {
|
|
@@ -22,7 +22,7 @@ export function removeFields(queryResults: any, fieldsToRemove: string[]): any {
|
|
|
22
22
|
|
|
23
23
|
export async function mapQueries(
|
|
24
24
|
queries: string[],
|
|
25
|
-
targetConnection: CachedConnection
|
|
25
|
+
targetConnection: CachedConnection,
|
|
26
26
|
): Promise<any[]> {
|
|
27
27
|
const mappedArray = [];
|
|
28
28
|
for (let i = 0; i < queries.length; i++) {
|