@quillsql/node 0.5.5 → 0.5.7

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.
@@ -82,7 +82,7 @@ exports.getSchemaBigQuery = getSchemaBigQuery;
82
82
  function getTablesBySchemaBigQuery(bigQuery, schemaNames) {
83
83
  return __awaiter(this, void 0, void 0, function* () {
84
84
  const allColumns = yield Promise.all(schemaNames.map((schema) => __awaiter(this, void 0, void 0, function* () {
85
- const sql = `SELECT table_name FROM ${schema}.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE'`;
85
+ const sql = `SELECT table_name FROM ${schema}.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE' OR table_type = 'VIEW' OR table_type = 'MATERIALIZED VIEW'`;
86
86
  const rows = yield bigQuery.query(sql);
87
87
  return rows[0].map((row) => {
88
88
  return { tableName: row.table_name, schemaName: schema };
package/dist/index.js CHANGED
@@ -41,9 +41,10 @@ class Quill {
41
41
  this.targetConnection = new CachedConnection_1.CachedConnection(databaseType, credentials, cache || {});
42
42
  }
43
43
  query({ orgId, metadata, }) {
44
- var _a, _b, _c;
44
+ var _a, _b;
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  this.targetConnection.orgId = orgId;
47
+ let responseMetadata = {};
47
48
  try {
48
49
  const preQueryResults = metadata.preQueries
49
50
  ? yield this.runQueries(metadata.preQueries, this.targetConnection.databaseType, metadata.databaseType, metadata.runQueryConfig)
@@ -59,16 +60,15 @@ class Quill {
59
60
  return { status: "error", error: response.error };
60
61
  }
61
62
  // if there is no metadata object in the response, create one
62
- if (!response.metadata) {
63
- response.metadata = {};
63
+ if (response.metadata) {
64
+ responseMetadata = response.metadata;
64
65
  }
65
- const results = yield this.runQueries(response.queries, this.targetConnection.databaseType, metadata.databaseType, response.metadata.runQueryConfig);
66
+ const results = yield this.runQueries(response.queries, this.targetConnection.databaseType, metadata.databaseType, responseMetadata.runQueryConfig);
66
67
  // QUICK JANKY FIX TO UPDATE METADATA AFTER GETTING MAPPED ARRAYS
67
- if (results.mappedArray &&
68
- ((_c = (_b = response.metadata) === null || _b === void 0 ? void 0 : _b.runQueryConfig) === null || _c === void 0 ? void 0 : _c.arrayToMap)) {
69
- const arrayToMap = response.metadata.runQueryConfig.arrayToMap;
68
+ if (results.mappedArray && ((_b = responseMetadata.runQueryConfig) === null || _b === void 0 ? void 0 : _b.arrayToMap)) {
69
+ const arrayToMap = responseMetadata.runQueryConfig.arrayToMap;
70
70
  results.mappedArray.forEach((array, index) => {
71
- response.metadata[arrayToMap.arrayName][index][arrayToMap.field] =
71
+ responseMetadata[arrayToMap.arrayName][index][arrayToMap.field] =
72
72
  array;
73
73
  });
74
74
  delete results.mappedArray;
@@ -77,20 +77,24 @@ class Quill {
77
77
  if ((results === null || results === void 0 ? void 0 : results.queryResults.length) === 1) {
78
78
  const queryResults = results.queryResults[0];
79
79
  if (queryResults.rows) {
80
- response.metadata.rows = queryResults.rows;
80
+ responseMetadata.rows = queryResults.rows;
81
81
  }
82
82
  if (queryResults.fields) {
83
- response.metadata.fields = queryResults.fields;
83
+ responseMetadata.fields = queryResults.fields;
84
84
  }
85
85
  }
86
86
  return {
87
- data: response.metadata || null,
87
+ data: responseMetadata,
88
88
  queries: results,
89
89
  status: "success",
90
90
  };
91
91
  }
92
92
  catch (err) {
93
- return { status: "error", error: err.message };
93
+ return {
94
+ status: "error",
95
+ error: err.message,
96
+ data: responseMetadata,
97
+ };
94
98
  }
95
99
  });
96
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Quill Server SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -84,7 +84,7 @@ export async function getTablesBySchemaBigQuery(
84
84
  ): Promise<{ tableName: string; schemaName: string }[]> {
85
85
  const allColumns = await Promise.all(
86
86
  schemaNames.map(async (schema) => {
87
- const sql = `SELECT table_name FROM ${schema}.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE'`;
87
+ const sql = `SELECT table_name FROM ${schema}.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE' OR table_type = 'VIEW' OR table_type = 'MATERIALIZED VIEW'`;
88
88
  const rows = await bigQuery.query(sql);
89
89
  return rows[0].map((row) => {
90
90
  return { tableName: row.table_name, schemaName: schema };
package/src/index.ts CHANGED
@@ -91,6 +91,7 @@ export class Quill {
91
91
  metadata,
92
92
  }: QuillQueryParams): Promise<QuillQueryResult> {
93
93
  this.targetConnection.orgId = orgId;
94
+ let responseMetadata: any = {};
94
95
  try {
95
96
  const preQueryResults = metadata.preQueries
96
97
  ? await this.runQueries(
@@ -116,23 +117,20 @@ export class Quill {
116
117
  return { status: "error", error: response.error };
117
118
  }
118
119
  // if there is no metadata object in the response, create one
119
- if (!response.metadata) {
120
- response.metadata = {};
120
+ if (response.metadata) {
121
+ responseMetadata = response.metadata;
121
122
  }
122
123
  const results = await this.runQueries(
123
124
  response.queries,
124
125
  this.targetConnection.databaseType,
125
126
  metadata.databaseType,
126
- response.metadata.runQueryConfig
127
+ responseMetadata.runQueryConfig
127
128
  );
128
129
  // QUICK JANKY FIX TO UPDATE METADATA AFTER GETTING MAPPED ARRAYS
129
- if (
130
- results.mappedArray &&
131
- response.metadata?.runQueryConfig?.arrayToMap
132
- ) {
133
- const arrayToMap = response.metadata.runQueryConfig.arrayToMap;
130
+ if (results.mappedArray && responseMetadata.runQueryConfig?.arrayToMap) {
131
+ const arrayToMap = responseMetadata.runQueryConfig.arrayToMap;
134
132
  results.mappedArray.forEach((array: any, index: number) => {
135
- response.metadata[arrayToMap.arrayName][index][arrayToMap.field] =
133
+ responseMetadata[arrayToMap.arrayName][index][arrayToMap.field] =
136
134
  array;
137
135
  });
138
136
  delete results.mappedArray;
@@ -141,19 +139,23 @@ export class Quill {
141
139
  if (results?.queryResults.length === 1) {
142
140
  const queryResults = results.queryResults[0];
143
141
  if (queryResults.rows) {
144
- response.metadata.rows = queryResults.rows;
142
+ responseMetadata.rows = queryResults.rows;
145
143
  }
146
144
  if (queryResults.fields) {
147
- response.metadata.fields = queryResults.fields;
145
+ responseMetadata.fields = queryResults.fields;
148
146
  }
149
147
  }
150
148
  return {
151
- data: response.metadata || null,
149
+ data: responseMetadata,
152
150
  queries: results,
153
151
  status: "success",
154
152
  };
155
153
  } catch (err) {
156
- return { status: "error", error: (err as any).message };
154
+ return {
155
+ status: "error",
156
+ error: (err as any).message,
157
+ data: responseMetadata,
158
+ };
157
159
  }
158
160
  }
159
161