@quillsql/node 0.4.0 → 0.4.2

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.
@@ -173,9 +173,18 @@ function inferType(elem) {
173
173
  // Check if the number is a float or an integer
174
174
  return Number.isInteger(elem) ? 23 : 700; // 23: integer, 700: real
175
175
  }
176
+ // BIG QUERY places data into objects as well
176
177
  if (typeof elem === "object") {
177
178
  if (/^\d{4}-\d{2}-\d{2}$/.test(elem.value))
178
- return 1082; // date
179
+ return 1082; // YYYY-MM-DD format
180
+ if (/^\d{2}\/\d{2}\/\d{2,4}$/.test(elem.value))
181
+ return 1082; // MM\DD\YYYY or MM\DD\YY format
182
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/.test(elem.value))
183
+ return 1114; // YYYY-MM-DDTHH:MM:SS[.fraction] format
184
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/.test(elem.value))
185
+ return 1184; // YYYY-MM-DDTHH:MM:SS[.fraction]Z format
186
+ if (/^\d{2}:\d{2}:\d{2}$/.test(elem.value))
187
+ return 1083; // HH:MM:SS format
179
188
  }
180
189
  if (typeof elem === "string") {
181
190
  // Attempt to infer date, time, and timestamp formats
package/dist/index.js CHANGED
@@ -49,6 +49,9 @@ class QuillClass {
49
49
  };
50
50
  }
51
51
  const response = yield this.postQuill(metadata.task, Object.assign(Object.assign(Object.assign({}, metadata), preQueryResults), { orgId, viewQuery: metadata.preQueries ? metadata.preQueries[0] : undefined }));
52
+ if (response.error) {
53
+ return { status: "error", error: response.error };
54
+ }
52
55
  // if there is no metadata object in the response, create one
53
56
  if (!response.metadata) {
54
57
  response.metadata = {};
@@ -103,7 +106,7 @@ class QuillClass {
103
106
  return Object.assign(Object.assign({}, results), { queryResults: [], mappedArray });
104
107
  }
105
108
  else if (runQueryConfig === null || runQueryConfig === void 0 ? void 0 : runQueryConfig.getColumns) {
106
- const queryResult = yield this.targetConnection.query(`${queries[0]} limit 1`);
109
+ const queryResult = yield this.targetConnection.query(`${queries[0].replace(/;/, "")} limit 1`);
107
110
  const columns = queryResult.fields.map((field) => {
108
111
  return {
109
112
  fieldType: (0, schemaConversion_1.convertTypeToPostgres)(field.dataTypeID),
@@ -126,6 +129,11 @@ class QuillClass {
126
129
  return query.replace(/;/, "") + " limit 1000;";
127
130
  });
128
131
  }
132
+ else if (runQueryConfig === null || runQueryConfig === void 0 ? void 0 : runQueryConfig.limitBy) {
133
+ queries = queries.map((query) => {
134
+ return query.replace(/;/, "") + " limit " + runQueryConfig.limitBy;
135
+ });
136
+ }
129
137
  const queryResults = yield Promise.all(queries.map((query) => __awaiter(this, void 0, void 0, function* () {
130
138
  return yield this.targetConnection.query(query);
131
139
  })));
@@ -4,7 +4,7 @@ import express from "express";
4
4
  import cors from "cors";
5
5
 
6
6
  const app = express();
7
- const port = 3001;
7
+ const port = 3000;
8
8
 
9
9
  // postgresqlConfigExample {
10
10
  // connectionString: process.env.DB_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Quill's client SDK for node backends.",
5
5
  "main": "dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -36,4 +36,4 @@
36
36
  "snowflake-sdk": "^1.9.3",
37
37
  "ts-jest": "^29.1.1"
38
38
  }
39
- }
39
+ }
@@ -190,8 +190,15 @@ function inferType(elem: any) {
190
190
  // Check if the number is a float or an integer
191
191
  return Number.isInteger(elem) ? 23 : 700; // 23: integer, 700: real
192
192
  }
193
+ // BIG QUERY places data into objects as well
193
194
  if (typeof elem === "object") {
194
- if (/^\d{4}-\d{2}-\d{2}$/.test(elem.value)) return 1082; // date
195
+ if (/^\d{4}-\d{2}-\d{2}$/.test(elem.value)) return 1082; // YYYY-MM-DD format
196
+ if (/^\d{2}\/\d{2}\/\d{2,4}$/.test(elem.value)) return 1082; // MM\DD\YYYY or MM\DD\YY format
197
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/.test(elem.value))
198
+ return 1114; // YYYY-MM-DDTHH:MM:SS[.fraction] format
199
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/.test(elem.value))
200
+ return 1184; // YYYY-MM-DDTHH:MM:SS[.fraction]Z format
201
+ if (/^\d{2}:\d{2}:\d{2}$/.test(elem.value)) return 1083; // HH:MM:SS format
195
202
  }
196
203
  if (typeof elem === "string") {
197
204
  // Attempt to infer date, time, and timestamp formats
package/src/index.ts CHANGED
@@ -88,6 +88,9 @@ export default class QuillClass {
88
88
  orgId,
89
89
  viewQuery: metadata.preQueries ? metadata.preQueries[0] : undefined,
90
90
  });
91
+ if (response.error) {
92
+ return { status: "error", error: response.error };
93
+ }
91
94
  // if there is no metadata object in the response, create one
92
95
  if (!response.metadata) {
93
96
  response.metadata = {};
@@ -153,7 +156,7 @@ export default class QuillClass {
153
156
  return { ...results, queryResults: [], mappedArray };
154
157
  } else if (runQueryConfig?.getColumns) {
155
158
  const queryResult = await this.targetConnection.query(
156
- `${queries[0]} limit 1`
159
+ `${queries[0].replace(/;/, "")} limit 1`
157
160
  );
158
161
  const columns = queryResult.fields.map((field: any) => {
159
162
  return {
@@ -183,6 +186,10 @@ export default class QuillClass {
183
186
  queries = queries.map((query) => {
184
187
  return query.replace(/;/, "") + " limit 1000;";
185
188
  });
189
+ } else if (runQueryConfig?.limitBy) {
190
+ queries = queries.map((query) => {
191
+ return query.replace(/;/, "") + " limit " + runQueryConfig.limitBy;
192
+ });
186
193
  }
187
194
  const queryResults = await Promise.all(
188
195
  queries.map(async (query) => {
@@ -26,7 +26,7 @@ export interface QuillRequestMetadata {
26
26
  template?: boolean;
27
27
  clientId?: string;
28
28
  deleted?: boolean;
29
- databaseType?: string
29
+ databaseType?: string;
30
30
  }
31
31
 
32
32
  export interface QuillQueryParams {
@@ -55,18 +55,20 @@ export interface AdditionalProcessing {
55
55
  getSchema?: boolean;
56
56
  getColumns?: boolean;
57
57
  getTables?: boolean;
58
- schema?: string,
58
+ schema?: string;
59
59
  schemaNames?: string[];
60
- table?: string,
60
+ table?: string;
61
61
  removeFields?: string[];
62
62
  arrayToMap?: { arrayName: string; field: string };
63
63
  overridePost?: boolean;
64
- convertDatatypes?: boolean
64
+ convertDatatypes?: boolean;
65
65
  limitThousand?: boolean;
66
+ limitBy?: number;
66
67
  }
67
68
 
68
69
  export interface QuillClientResponse {
69
70
  queries: string[];
70
71
  metadata: any;
71
72
  runQueryConfig: AdditionalProcessing;
73
+ error?: string;
72
74
  }