@quillsql/node 0.6.2 → 0.6.4

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.
@@ -19,7 +19,6 @@ export interface QuillQueryResults {
19
19
  export declare function getDatabaseCredentials(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string): PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig;
20
20
  export declare function connectToDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", config: PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig): DatabaseConnection;
21
21
  export declare function withConnection<T>(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string, callback: (connection: DatabaseConnection) => T): Promise<T>;
22
- export declare function withPool<T>(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", pool: DatabaseConnection, callback: (connection: DatabaseConnection) => T): Promise<T>;
23
22
  export declare function runQueryByDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connection: DatabaseConnection, sql: string): Promise<QuillQueryResults> | undefined;
24
23
  export declare function connectAndRunQuery(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string, sql: string): Promise<QuillQueryResults | undefined>;
25
24
  export declare function disconnectFromDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", database: DatabaseConnection): void | Promise<void>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getColumnInfoBySchemaByDatabase = exports.getForiegnKeysByDatabase = exports.getColumnsByTableByDatabase = exports.getTablesBySchemaByDatabase = exports.getSchemasByDatabase = exports.disconnectFromDatabase = exports.connectAndRunQuery = exports.runQueryByDatabase = exports.withPool = exports.withConnection = exports.connectToDatabase = exports.getDatabaseCredentials = void 0;
12
+ exports.getColumnInfoBySchemaByDatabase = exports.getForiegnKeysByDatabase = exports.getColumnsByTableByDatabase = exports.getTablesBySchemaByDatabase = exports.getSchemasByDatabase = exports.disconnectFromDatabase = exports.connectAndRunQuery = exports.runQueryByDatabase = exports.withConnection = exports.connectToDatabase = exports.getDatabaseCredentials = void 0;
13
13
  const Postgres_1 = require("./Postgres");
14
14
  const Snowflake_1 = require("./Snowflake");
15
15
  const BigQuery_1 = require("./BigQuery");
@@ -55,23 +55,15 @@ function withConnection(databaseType, connectionString, callback) {
55
55
  try {
56
56
  return yield callback(connection);
57
57
  }
58
+ catch (e) {
59
+ return new Promise((_, reject) => reject({ success: false, message: e.message || e.error || e }));
60
+ }
58
61
  finally {
59
62
  yield disconnectFromDatabase(databaseType, connection);
60
63
  }
61
64
  });
62
65
  }
63
66
  exports.withConnection = withConnection;
64
- function withPool(databaseType, pool, callback) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- try {
67
- return yield callback(pool);
68
- }
69
- finally {
70
- yield disconnectFromDatabase(databaseType, pool);
71
- }
72
- });
73
- }
74
- exports.withPool = withPool;
75
67
  function runQueryByDatabase(databaseType, connection, sql) {
76
68
  switch (databaseType.toLowerCase()) {
77
69
  case "postgres":
package/dist/db/Mysql.js CHANGED
@@ -29,7 +29,7 @@ function formatMysqlConfig(connectionString) {
29
29
  }
30
30
  exports.formatMysqlConfig = formatMysqlConfig;
31
31
  function connectToMysql(config) {
32
- const pool = mysql2_1.default.createPool(Object.assign(Object.assign({}, config), { waitForConnections: true, connectionLimit: 128, queueLimit: 0 }));
32
+ const pool = mysql2_1.default.createPool(Object.assign(Object.assign({}, config), { waitForConnections: true, connectionLimit: 24, queueLimit: 0 }));
33
33
  return pool;
34
34
  }
35
35
  exports.connectToMysql = connectToMysql;
@@ -157,43 +157,77 @@ function getSchemaColumnInfoMysql(connection, schemaName, tableNames) {
157
157
  exports.getSchemaColumnInfoMysql = getSchemaColumnInfoMysql;
158
158
  function mysqlTextDataTypeToPostgresOID(type) {
159
159
  switch (type) {
160
- case "bigint": // int
161
- return 23;
162
- case "tinyint": // int
163
- return 23;
164
- case "float": // float
165
- return 700;
166
- case "varchar": // varchar
167
- return 1043;
168
- case "timestamp": // date
169
- return 1082;
170
- case "date": // date
171
- return 1082;
172
- case "datetime": // date
173
- return 1082;
174
- default: // varchar
175
- return 1043;
160
+ case "bigint": // BIGINT in MySQL
161
+ return 20; // BIGINT in PostgreSQL
162
+ case "tinyint": // TINYINT in MySQL
163
+ return 21; // SMALLINT in PostgreSQL
164
+ case "smallint": // SMALLINT in MySQL
165
+ return 21; // SMALLINT in PostgreSQL
166
+ case "int": // INT in MySQL
167
+ return 23; // INTEGER in PostgreSQL
168
+ case "float": // FLOAT in MySQL
169
+ return 701; // DOUBLE PRECISION in PostgreSQL
170
+ case "double": // DOUBLE in MySQL
171
+ return 701; // DOUBLE PRECISION in PostgreSQL
172
+ case "varchar": // VARCHAR in MySQL
173
+ return 1043; // VARCHAR in PostgreSQL
174
+ case "char": // CHAR in MySQL
175
+ return 1042; // CHAR in PostgreSQL
176
+ case "timestamp": // TIMESTAMP in MySQL
177
+ return 1114; // TIMESTAMP in PostgreSQL
178
+ case "date": // DATE in MySQL
179
+ return 1082; // DATE in PostgreSQL
180
+ case "datetime": // DATETIME in MySQL
181
+ return 1114; // TIMESTAMP in PostgreSQL
182
+ case "time": // TIME in MySQL
183
+ return 1083; // TIME in PostgreSQL
184
+ case "year": // YEAR in MySQL
185
+ return 23; // INTEGER in PostgreSQL
186
+ case "binary": // BINARY in MySQL
187
+ return 17; // BYTEA in PostgreSQL
188
+ case "blob": // BLOB in MySQL
189
+ return 17; // BYTEA in PostgreSQL
190
+ case "text": // TEXT in MySQL
191
+ return 25; // TEXT in PostgreSQL
192
+ case "json": // JSON in MySQL
193
+ return 114; // JSON in PostgreSQL
194
+ default:
195
+ return 1043; // VARCHAR in PostgreSQL (fallback)
176
196
  }
177
197
  }
178
198
  function mysqlDataTypeIdToPostgresType(type) {
179
199
  switch (type) {
180
- case 8: // int
181
- return 23;
182
- case 3: // int
183
- return 23;
184
- case 2: // int
185
- return 23;
186
- case 5: // float
187
- return 700;
188
- case 253: // varchar
189
- return 1043;
190
- case 7: // date
191
- return 1082;
192
- case 10: // date
193
- return 1082;
194
- case 12: // date
195
- return 1082;
196
- default: // varchar
197
- return 1043;
200
+ case 0: // DECIMAL
201
+ case 1: // TINY
202
+ case 2: // SHORT
203
+ case 3: // LONG
204
+ case 8: // LONGLONG
205
+ case 9: // INT24
206
+ case 13: // YEAR
207
+ return 23; // INTEGER
208
+ case 4: // FLOAT
209
+ case 5: // DOUBLE
210
+ return 701; // DOUBLE PRECISION
211
+ case 7: // TIMESTAMP
212
+ case 12: // DATETIME
213
+ return 1114; // TIMESTAMP
214
+ case 10: // DATE
215
+ case 242: // NEWDATE
216
+ return 1082; // DATE
217
+ case 15: // VARCHAR
218
+ case 25: // VAR_STRING
219
+ case 250: // STRING
220
+ case 254: // ENUM
221
+ case 255: // SET
222
+ return 1043; // VARCHAR
223
+ case 16: // BIT
224
+ case 245: // TINY_BLOB
225
+ case 246: // MEDIUM_BLOB
226
+ case 247: // LONG_BLOB
227
+ case 248: // BLOB
228
+ case 251: // GEOMETRY
229
+ return 17; // BYTEA
230
+ default:
231
+ return 1043; // Default to VARCHAR if unknown
198
232
  }
199
233
  }
package/dist/index.js CHANGED
@@ -41,7 +41,7 @@ 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, _d, _e;
44
+ var _a, _b;
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  this.targetConnection.orgId = orgId;
47
47
  let responseMetadata = {};
@@ -99,7 +99,7 @@ class Quill {
99
99
  catch (err) {
100
100
  return {
101
101
  status: "error",
102
- error: (_e = (_d = (_c = err.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.error) !== null && _e !== void 0 ? _e : err.message,
102
+ error: err.message,
103
103
  data: responseMetadata || {},
104
104
  };
105
105
  }
@@ -216,8 +216,13 @@ class Quill {
216
216
  }
217
217
  postQuill(path, payload) {
218
218
  return __awaiter(this, void 0, void 0, function* () {
219
- const response = yield axios_1.default.post(`${this.baseUrl}/sdk/${path}`, payload, this.config);
220
- return response.data;
219
+ try {
220
+ const response = yield axios_1.default.post(`${this.baseUrl}/sdk/${path}`, payload, this.config);
221
+ return response.data;
222
+ }
223
+ catch (e) {
224
+ return new Promise((_, reject) => { var _a, _b; return reject({ message: ((_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || e.message || e }); });
225
+ }
221
226
  });
222
227
  }
223
228
  [Symbol.asyncDispose]() {
@@ -245,7 +250,6 @@ const requireQuill = ({ privateKey, databaseConnectionString, databaseConfig, ca
245
250
  module.exports = requireQuill;
246
251
  module.exports.default = requireQuill;
247
252
  module.exports.withConnection = DatabaseHelper_1.withConnection;
248
- module.exports.withPool = DatabaseHelper_1.withPool;
249
253
  module.exports.connectToDatabase = DatabaseHelper_1.connectToDatabase;
250
254
  module.exports.connectAndRunQuery = DatabaseHelper_1.connectAndRunQuery;
251
255
  module.exports.Quill = Quill;
@@ -2,7 +2,6 @@
2
2
 
3
3
  import express from "express";
4
4
  import cors from "cors";
5
- import requireQuill from "../../src/index";
6
5
 
7
6
  const app = express();
8
7
  const port = 3005;
@@ -41,7 +40,7 @@ app.get("/", (req, res) => {
41
40
  res.send("Hello World!");
42
41
  });
43
42
 
44
- const quill = requireQuill({
43
+ const quill = require("../../src/index")({
45
44
  privateKey: process.env.MYSQL_PRIVATE_KEY ?? "",
46
45
  databaseConnectionString: process.env.MYSQL_DB_URL ?? "",
47
46
  databaseConfig: {}, // TODO: Add database config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Quill Server SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -119,23 +119,15 @@ export async function withConnection<T>(
119
119
  const connection = connectToDatabase(databaseType, config);
120
120
  try {
121
121
  return await callback(connection);
122
+ } catch (e: any) {
123
+ return new Promise((_, reject) =>
124
+ reject({ success: false, message: e.message || e.error || e }),
125
+ );
122
126
  } finally {
123
127
  await disconnectFromDatabase(databaseType, connection);
124
128
  }
125
129
  }
126
130
 
127
- export async function withPool<T>(
128
- databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql",
129
- pool: DatabaseConnection,
130
- callback: (connection: DatabaseConnection) => T,
131
- ): Promise<T> {
132
- try {
133
- return await callback(pool);
134
- } finally {
135
- await disconnectFromDatabase(databaseType, pool);
136
- }
137
- }
138
-
139
131
  export function runQueryByDatabase(
140
132
  databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql",
141
133
  connection: DatabaseConnection,
package/src/db/Mysql.ts CHANGED
@@ -29,7 +29,7 @@ export function connectToMysql(config: MysqlConnectionConfig): MysqlPool {
29
29
  const pool = mysql.createPool({
30
30
  ...config,
31
31
  waitForConnections: true,
32
- connectionLimit: 128,
32
+ connectionLimit: 24,
33
33
  queueLimit: 0,
34
34
  });
35
35
  return pool;
@@ -179,44 +179,84 @@ export async function getSchemaColumnInfoMysql(
179
179
 
180
180
  function mysqlTextDataTypeToPostgresOID(type: string): number {
181
181
  switch (type) {
182
- case "bigint": // int
183
- return 23;
184
- case "tinyint": // int
185
- return 23;
186
- case "float": // float
187
- return 700;
188
- case "varchar": // varchar
189
- return 1043;
190
- case "timestamp": // date
191
- return 1082;
192
- case "date": // date
193
- return 1082;
194
- case "datetime": // date
195
- return 1082;
196
- default: // varchar
197
- return 1043;
182
+ case "bigint": // BIGINT in MySQL
183
+ return 20; // BIGINT in PostgreSQL
184
+ case "tinyint": // TINYINT in MySQL
185
+ return 21; // SMALLINT in PostgreSQL
186
+ case "smallint": // SMALLINT in MySQL
187
+ return 21; // SMALLINT in PostgreSQL
188
+ case "int": // INT in MySQL
189
+ return 23; // INTEGER in PostgreSQL
190
+ case "float": // FLOAT in MySQL
191
+ return 701; // DOUBLE PRECISION in PostgreSQL
192
+ case "double": // DOUBLE in MySQL
193
+ return 701; // DOUBLE PRECISION in PostgreSQL
194
+ case "varchar": // VARCHAR in MySQL
195
+ return 1043; // VARCHAR in PostgreSQL
196
+ case "char": // CHAR in MySQL
197
+ return 1042; // CHAR in PostgreSQL
198
+ case "timestamp": // TIMESTAMP in MySQL
199
+ return 1114; // TIMESTAMP in PostgreSQL
200
+ case "date": // DATE in MySQL
201
+ return 1082; // DATE in PostgreSQL
202
+ case "datetime": // DATETIME in MySQL
203
+ return 1114; // TIMESTAMP in PostgreSQL
204
+ case "time": // TIME in MySQL
205
+ return 1083; // TIME in PostgreSQL
206
+ case "year": // YEAR in MySQL
207
+ return 23; // INTEGER in PostgreSQL
208
+ case "binary": // BINARY in MySQL
209
+ return 17; // BYTEA in PostgreSQL
210
+ case "blob": // BLOB in MySQL
211
+ return 17; // BYTEA in PostgreSQL
212
+ case "text": // TEXT in MySQL
213
+ return 25; // TEXT in PostgreSQL
214
+ case "json": // JSON in MySQL
215
+ return 114; // JSON in PostgreSQL
216
+ default:
217
+ return 1043; // VARCHAR in PostgreSQL (fallback)
198
218
  }
199
219
  }
200
220
 
201
221
  function mysqlDataTypeIdToPostgresType(type: number): number {
202
222
  switch (type) {
203
- case 8: // int
204
- return 23;
205
- case 3: // int
206
- return 23;
207
- case 2: // int
208
- return 23;
209
- case 5: // float
210
- return 700;
211
- case 253: // varchar
212
- return 1043;
213
- case 7: // date
214
- return 1082;
215
- case 10: // date
216
- return 1082;
217
- case 12: // date
218
- return 1082;
219
- default: // varchar
220
- return 1043;
223
+ case 0: // DECIMAL
224
+ case 1: // TINY
225
+ case 2: // SHORT
226
+ case 3: // LONG
227
+ case 8: // LONGLONG
228
+ case 9: // INT24
229
+ case 13: // YEAR
230
+ return 23; // INTEGER
231
+
232
+ case 4: // FLOAT
233
+ case 5: // DOUBLE
234
+ return 701; // DOUBLE PRECISION
235
+
236
+ case 7: // TIMESTAMP
237
+ case 12: // DATETIME
238
+ return 1114; // TIMESTAMP
239
+
240
+ case 10: // DATE
241
+ case 242: // NEWDATE
242
+ return 1082; // DATE
243
+
244
+ case 15: // VARCHAR
245
+ case 25: // VAR_STRING
246
+ case 250: // STRING
247
+ case 254: // ENUM
248
+ case 255: // SET
249
+ return 1043; // VARCHAR
250
+
251
+ case 16: // BIT
252
+ case 245: // TINY_BLOB
253
+ case 246: // MEDIUM_BLOB
254
+ case 247: // LONG_BLOB
255
+ case 248: // BLOB
256
+ case 251: // GEOMETRY
257
+ return 17; // BYTEA
258
+
259
+ default:
260
+ return 1043; // Default to VARCHAR if unknown
221
261
  }
222
262
  }
package/src/index.ts CHANGED
@@ -19,7 +19,6 @@ import {
19
19
  getTablesBySchemaByDatabase,
20
20
  runQueryByDatabase,
21
21
  withConnection,
22
- withPool,
23
22
  } from "./db/DatabaseHelper";
24
23
  import { convertTypeToPostgres } from "./utils/schemaConversion";
25
24
 
@@ -164,7 +163,7 @@ export class Quill implements AsyncDisposable {
164
163
  } catch (err) {
165
164
  return {
166
165
  status: "error",
167
- error: (err as any).response?.data?.error ?? (err as any).message,
166
+ error: (err as any).message,
168
167
  data: responseMetadata || {},
169
168
  };
170
169
  }
@@ -317,12 +316,18 @@ export class Quill implements AsyncDisposable {
317
316
  path: string,
318
317
  payload: any,
319
318
  ): Promise<QuillClientResponse> {
320
- const response = await axios.post(
321
- `${this.baseUrl}/sdk/${path}`,
322
- payload,
323
- this.config,
324
- );
325
- return response.data;
319
+ try {
320
+ const response = await axios.post(
321
+ `${this.baseUrl}/sdk/${path}`,
322
+ payload,
323
+ this.config,
324
+ );
325
+ return response.data;
326
+ } catch (e: any) {
327
+ return new Promise((_, reject) =>
328
+ reject({ message: e?.response?.data?.error || e.message || e }),
329
+ );
330
+ }
326
331
  }
327
332
 
328
333
  public async [Symbol.asyncDispose](): Promise<void> {
@@ -362,7 +367,6 @@ const requireQuill = ({
362
367
  module.exports = requireQuill;
363
368
  module.exports.default = requireQuill;
364
369
  module.exports.withConnection = withConnection;
365
- module.exports.withPool = withPool;
366
370
  module.exports.connectToDatabase = connectToDatabase;
367
371
  module.exports.connectAndRunQuery = connectAndRunQuery;
368
372
  module.exports.Quill = Quill;