@quillsql/node 0.3.8 → 0.4.1

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.
@@ -9,22 +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.mapQueries = exports.removeFields = exports.getTableSchema = void 0;
13
- function getTableSchema(queryResults, targetConnection) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const typesQuery = yield targetConnection.query("select typname, oid, typarray from pg_type order by oid;");
16
- const schema = queryResults[0].fields.map((field) => {
17
- return {
18
- fieldType: typesQuery.rows.filter((type) => field.dataTypeID === type.oid)[0].typname,
19
- name: field.name,
20
- displayName: field.name,
21
- isVisible: true,
22
- };
23
- });
24
- return schema;
25
- });
26
- }
27
- exports.getTableSchema = getTableSchema;
12
+ exports.mapQueries = exports.removeFields = void 0;
28
13
  function removeFields(queryResults, fieldsToRemove) {
29
14
  const fields = queryResults.fields.filter((field) => fieldsToRemove.includes(field.name));
30
15
  const rows = queryResults.map((row) => {
@@ -35,7 +20,7 @@ function removeFields(queryResults, fieldsToRemove) {
35
20
  });
36
21
  }
37
22
  exports.removeFields = removeFields;
38
- function mapQueries(queries, arrayToMap, targetConnection) {
23
+ function mapQueries(queries, targetConnection) {
39
24
  return __awaiter(this, void 0, void 0, function* () {
40
25
  const mappedArray = [];
41
26
  for (let i = 0; i < queries.length; i++) {
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertTypeToPostgres = void 0;
4
+ const pgtypes_1 = require("../assets/pgtypes");
5
+ function convertTypeToPostgres(data_type_id) {
6
+ var _a;
7
+ const type = pgtypes_1.PG_TYPES.find((type) => data_type_id === type.oid)
8
+ ? (_a = pgtypes_1.PG_TYPES.find((type) => data_type_id === type.oid)) === null || _a === void 0 ? void 0 : _a.typname
9
+ : undefined;
10
+ if (!type) {
11
+ return "varchar";
12
+ }
13
+ return type;
14
+ }
15
+ exports.convertTypeToPostgres = convertTypeToPostgres;
@@ -4,11 +4,45 @@ 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
+
9
+ // postgresqlConfigExample {
10
+ // connectionString: process.env.DB_URL,
11
+ // ssl: {
12
+ // rejectUnauthorized: false,
13
+ // },
14
+ // };
15
+
16
+ // bigqueryConfigExample {
17
+ // projectId: process.env.PROJECT_ID,
18
+ // credentials: serviceAccount // You need to make the serviceAccount JSON
19
+ // }
20
+
21
+ // snowflakeConfigExample {
22
+ // account: process.env.ACCOUNT,
23
+ // username: process.env.USERNAME,
24
+ // password: process.env.PASSWORD,
25
+ // warehouse: process.env.WAREHOUSE,
26
+ // database: process.env.DATABASE,
27
+ // }
28
+
29
+ // mysqlConfigExample {
30
+ // host: process.env.HOST,
31
+ // user: process.env.USER,
32
+ // password: process.env.PASSWORD,
33
+ // database: process.env.DATABASE,
34
+ // }
8
35
 
9
36
  const quill = require("../../src/index")({
10
- privateKey: process.env.QUILL_PRIVATE_KEY,
37
+ privateKey: process.env.PRIVATE_KEY,
11
38
  databaseConnectionString: process.env.DB_URL,
39
+ // databaseConfig: {
40
+ // connectionString: process.env.DB_URL,
41
+ // ssl: {
42
+ // rejectUnauthorized: false,
43
+ // },
44
+ // },
45
+ databaseType: process.env.DB_TYPE,
12
46
  });
13
47
 
14
48
  app.use(cors());
@@ -19,7 +53,6 @@ app.get("/", (req, res) => {
19
53
  });
20
54
 
21
55
  app.post("/quill", async (req, res) => {
22
- const organizationId = req.body.orgId;
23
56
  const { metadata } = req.body;
24
57
  const result = await quill.query({
25
58
  orgId: metadata.orgId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.3.8",
3
+ "version": "0.4.1",
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
+ }
@@ -9,6 +9,35 @@ export interface BigQueryConfig {
9
9
  credentials: any;
10
10
  }
11
11
 
12
+ export function formatBigQueryConfig(connectionString: string): BigQueryConfig {
13
+ const jsonStartIndex = connectionString.indexOf("{");
14
+ if (jsonStartIndex === -1) {
15
+ throw new Error("Invalid input string. No JSON data found.");
16
+ }
17
+
18
+ const datasetName = connectionString.substring(0, jsonStartIndex).trim();
19
+ const jsonString = connectionString.substring(jsonStartIndex);
20
+
21
+ try {
22
+ const serviceAccount = JSON.parse(jsonString);
23
+
24
+ // Validate if required fields are present
25
+ if (!serviceAccount.project_id || !serviceAccount.private_key) {
26
+ throw new Error(
27
+ "Invalid service account JSON. Required fields are missing."
28
+ );
29
+ }
30
+
31
+ return {
32
+ datasetName,
33
+ projectId: serviceAccount.project_id,
34
+ credentials: serviceAccount,
35
+ };
36
+ } catch (error) {
37
+ throw new Error("Failed to parse JSON string: " + error);
38
+ }
39
+ }
40
+
12
41
  export function connectToBigQuery(config: BigQueryConfig) {
13
42
  return new BigQuery(config);
14
43
  }
@@ -51,11 +80,18 @@ export async function getSchemaBigQuery(bigQuery: BigQuery): Promise<string[]> {
51
80
 
52
81
  export async function getTablesBySchemaBigQuery(
53
82
  bigQuery: BigQuery,
54
- schemaName: string
55
- ): Promise<string[]> {
56
- const sql = `SELECT table_name FROM ${schemaName}.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE'`;
57
- const rows = await bigQuery.query(sql);
58
- return rows[0].map((row: any) => row.table_name);
83
+ schemaNames: string[]
84
+ ): Promise<{ tableName: string; schemaName: string }[]> {
85
+ const allColumns = await Promise.all(
86
+ schemaNames.map(async (schema) => {
87
+ const sql = `SELECT table_name FROM ${schema}.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE'`;
88
+ const rows = await bigQuery.query(sql);
89
+ return rows[0].map((row) => {
90
+ return { tableName: row.table_name, schemaName: schema };
91
+ });
92
+ })
93
+ );
94
+ return allColumns.flat();
59
95
  }
60
96
 
61
97
  export async function getColumnsByTableBigQuery(
@@ -68,35 +104,6 @@ export async function getColumnsByTableBigQuery(
68
104
  return rows[0].map((row: any) => row.column_name);
69
105
  }
70
106
 
71
- export function formatBigQueryConfig(connectionString: string): BigQueryConfig {
72
- const jsonStartIndex = connectionString.indexOf("{");
73
- if (jsonStartIndex === -1) {
74
- throw new Error("Invalid input string. No JSON data found.");
75
- }
76
-
77
- const datasetName = connectionString.substring(0, jsonStartIndex).trim();
78
- const jsonString = connectionString.substring(jsonStartIndex);
79
-
80
- try {
81
- const serviceAccount = JSON.parse(jsonString);
82
-
83
- // Validate if required fields are present
84
- if (!serviceAccount.project_id || !serviceAccount.private_key) {
85
- throw new Error(
86
- "Invalid service account JSON. Required fields are missing."
87
- );
88
- }
89
-
90
- return {
91
- datasetName,
92
- projectId: serviceAccount.project_id,
93
- credentials: serviceAccount,
94
- };
95
- } catch (error) {
96
- throw new Error("Failed to parse JSON string: " + error);
97
- }
98
- }
99
-
100
107
  export async function getForeignKeysBigQuery(
101
108
  connection: BigQuery,
102
109
  schemaName: string,
@@ -137,26 +144,26 @@ export async function getForeignKeysBigQuery(
137
144
  export async function getSchemaColumnInfoBigQuery(
138
145
  connection: BigQuery,
139
146
  schemaName: string,
140
- tableNames: string[]
147
+ tableNames: { tableName: string; schemaName: string }[]
141
148
  ): Promise<
142
- { tableName: string; columns: { columnName: string; dataTypeId: number }[] }[]
149
+ { tableName: string; columns: { columnName: string; dataTypeID: number }[] }[]
143
150
  > {
144
151
  const allColumns = await Promise.all(
145
152
  tableNames.map(async (tableName) => {
146
153
  const query = `
147
154
  SELECT column_name as columnName, data_type as dataType
148
- FROM ${schemaName}.INFORMATION_SCHEMA.COLUMNS
149
- WHERE table_name = '${tableName}'
155
+ FROM ${tableName.schemaName}.INFORMATION_SCHEMA.COLUMNS
156
+ WHERE table_name = '${tableName.tableName}'
150
157
  ORDER BY ordinal_position;
151
158
  `;
152
159
  const results = await runQueryBigQuery(query, connection);
153
160
  return {
154
- tableName,
155
- displayName: tableName,
161
+ tableName: `${tableName.schemaName}.${tableName.tableName}`,
162
+ displayName: `${tableName.schemaName}.${tableName.tableName}`,
156
163
  columns: results.rows.map((row: any) => ({
157
164
  columnName: row.columnName,
158
165
  displayName: row.columnName,
159
- dataTypeId: inferType(convertBigQueryTypeToPostgresOID(row.dataType)),
166
+ dataTypeID: convertBigQueryTypeToPostgresOID(row.dataType),
160
167
  fieldType: row.dataType,
161
168
  })),
162
169
  };
@@ -183,10 +190,22 @@ function inferType(elem: any) {
183
190
  // Check if the number is a float or an integer
184
191
  return Number.isInteger(elem) ? 23 : 700; // 23: integer, 700: real
185
192
  }
193
+ // BIG QUERY places data into objects as well
194
+ if (typeof elem === "object") {
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
202
+ }
186
203
  if (typeof elem === "string") {
187
204
  // Attempt to infer date, time, and timestamp formats
188
205
  // Date in YYYY-MM-DD format
189
206
  if (/^\d{4}-\d{2}-\d{2}$/.test(elem)) return 1082; // date
207
+ // Date in MM\DD\YYYY or MM\DD\YY format
208
+ if (/^\d{2}\/\d{2}\/\d{2,4}$/.test(elem)) return 1082; // date
190
209
  // Timestamp in YYYY-MM-DDTHH:MM:SS[.fraction] format
191
210
  if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/.test(elem)) return 1114; // timestamp without timezone
192
211
  // Timestamp in YYYY-MM-DDTHH:MM:SS[.fraction]Z format
@@ -53,10 +53,10 @@ import {
53
53
 
54
54
  export enum DatabaseType {
55
55
  postgres = "postgres",
56
- postgresql = "PostgreSQL",
57
- snowflake = "Snowflake",
58
- bigquery = "BigQuery",
59
- mysql = "MySQL",
56
+ postgresql = "postgresql",
57
+ snowflake = "snowflake",
58
+ bigquery = "bigquery",
59
+ mysql = "mysql",
60
60
  }
61
61
 
62
62
  // export all database connections types
@@ -80,16 +80,16 @@ export function getDatabaseCredentials(
80
80
  | BigQueryConfig
81
81
  | MysqlConnectionConfig
82
82
  | undefined {
83
- switch (databaseType) {
83
+ switch (databaseType.toLowerCase()) {
84
84
  case "postgres":
85
85
  return formatPostgresConfig(connectionString);
86
- case "PostgreSQL":
86
+ case "postgresql":
87
87
  return formatPostgresConfig(connectionString);
88
- case "Snowflake":
88
+ case "snowflake":
89
89
  return formatSnowflakeConfig(connectionString);
90
- case "BigQuery":
90
+ case "bigquery":
91
91
  return formatBigQueryConfig(connectionString);
92
- case "MySQL":
92
+ case "mysql":
93
93
  return formatMysqlConfig(connectionString);
94
94
  default:
95
95
  return undefined;
@@ -104,16 +104,16 @@ export function connectToDatabase(
104
104
  | BigQueryConfig
105
105
  | MysqlConnectionConfig
106
106
  ): DatabaseConnection {
107
- switch (databaseType) {
107
+ switch (databaseType.toLowerCase()) {
108
108
  case "postgres":
109
109
  return connectToPostgres(config as PostgresConnectionConfig);
110
- case "PostgreSQL":
110
+ case "postgresql":
111
111
  return connectToPostgres(config as PostgresConnectionConfig);
112
- case "Snowflake":
112
+ case "snowflake":
113
113
  return connectToSnowflake(config as SnowflakeConnectionConfig);
114
- case "BigQuery":
114
+ case "bigquery":
115
115
  return connectToBigQuery(config as BigQueryConfig);
116
- case "MySQL":
116
+ case "mysql":
117
117
  return connectToMysql(config as MysqlConnectionConfig);
118
118
  default:
119
119
  return connectToPostgres(config as PostgresConnectionConfig);
@@ -125,16 +125,16 @@ export function runQueryByDatabase(
125
125
  connection: DatabaseConnection,
126
126
  sql: string
127
127
  ): Promise<QuillQueryResults> | undefined {
128
- switch (databaseType) {
128
+ switch (databaseType.toLowerCase()) {
129
129
  case "postgres":
130
130
  return runQueryPostgres(sql, connection as Pool);
131
- case "PostgreSQL":
131
+ case "postgresql":
132
132
  return runQueryPostgres(sql, connection as Pool);
133
- case "Snowflake":
133
+ case "snowflake":
134
134
  return runQuerySnowflake(sql, connection as snowflake.Connection);
135
- case "BigQuery":
135
+ case "bigquery":
136
136
  return runQueryBigQuery(sql, connection as BigQuery);
137
- case "MySQL":
137
+ case "mysql":
138
138
  return runQueryMysql(sql, connection as MysqlPool);
139
139
  default:
140
140
  return undefined;
@@ -145,16 +145,16 @@ export function disconnectFromDatabase(
145
145
  databaseType: DatabaseType,
146
146
  database: DatabaseConnection
147
147
  ) {
148
- switch (databaseType) {
148
+ switch (databaseType.toLowerCase()) {
149
149
  case "postgres":
150
150
  return disconnectFromPostgres(database as Pool);
151
- case "PostgreSQL":
151
+ case "postgresql":
152
152
  return disconnectFromPostgres(database as Pool);
153
- case "Snowflake":
153
+ case "snowflake":
154
154
  return disconnectFromSnowflake(database as snowflake.Connection);
155
- case "BigQuery":
155
+ case "bigquery":
156
156
  return; // BigQuery does not need to be disconnected
157
- case "MySQL":
157
+ case "mysql":
158
158
  return disconnectFromMysql(database as MysqlPool);
159
159
  default:
160
160
  return undefined;
@@ -165,16 +165,16 @@ export async function getSchemasByDatabase(
165
165
  databaseType: DatabaseType,
166
166
  connection: DatabaseConnection
167
167
  ): Promise<string[] | undefined> {
168
- switch (databaseType) {
168
+ switch (databaseType.toLowerCase()) {
169
169
  case "postgres":
170
170
  return getSchemasPostgres(connection as Pool);
171
- case "PostgreSQL":
171
+ case "postgresql":
172
172
  return getSchemasPostgres(connection as Pool);
173
- case "Snowflake":
173
+ case "snowflake":
174
174
  return getSchemasSnowflake(connection as snowflake.Connection);
175
- case "BigQuery":
175
+ case "bigquery":
176
176
  return getSchemaBigQuery(connection as BigQuery);
177
- case "MySQL":
177
+ case "mysql":
178
178
  return getSchemasMysql(connection as MysqlPool);
179
179
  default:
180
180
  return undefined;
@@ -185,22 +185,34 @@ export async function getSchemasByDatabase(
185
185
  export async function getTablesBySchemaByDatabase(
186
186
  databaseType: DatabaseType,
187
187
  connection: DatabaseConnection,
188
- schemaName: string
189
- ): Promise<string[] | undefined> {
190
- switch (databaseType) {
188
+ schemaName: string | string[]
189
+ ): Promise<string[] | { tableName: string; schemaName: string }[] | undefined> {
190
+ switch (databaseType.toLowerCase()) {
191
191
  case "postgres":
192
- return getTablesBySchemaPostgres(connection as Pool, schemaName);
193
- case "PostgreSQL":
194
- return getTablesBySchemaPostgres(connection as Pool, schemaName);
195
- case "Snowflake":
192
+ return getTablesBySchemaPostgres(
193
+ connection as Pool,
194
+ schemaName as string[]
195
+ );
196
+ case "postgresql":
197
+ return getTablesBySchemaPostgres(
198
+ connection as Pool,
199
+ schemaName as string[]
200
+ );
201
+ case "snowflake":
196
202
  return getTablesBySchemaSnowflake(
197
203
  connection as snowflake.Connection,
198
- schemaName
204
+ schemaName as string[]
205
+ );
206
+ case "bigquery":
207
+ return getTablesBySchemaBigQuery(
208
+ connection as BigQuery,
209
+ schemaName as string[]
210
+ );
211
+ case "mysql":
212
+ return getTablesBySchemaMysql(
213
+ connection as MysqlPool,
214
+ schemaName as string[]
199
215
  );
200
- case "BigQuery":
201
- return getTablesBySchemaBigQuery(connection as BigQuery, schemaName);
202
- case "MySQL":
203
- return getTablesBySchemaMysql(connection as MysqlPool, schemaName);
204
216
  default:
205
217
  return undefined;
206
218
  }
@@ -213,32 +225,32 @@ export async function getColumnsByTableByDatabase(
213
225
  schemaName: string,
214
226
  tableName: string
215
227
  ): Promise<string[] | undefined> {
216
- switch (databaseType) {
228
+ switch (databaseType.toLowerCase()) {
217
229
  case "postgres":
218
230
  return getColumnsByTablePostgres(
219
231
  connection as Pool,
220
232
  schemaName,
221
233
  tableName
222
234
  );
223
- case "PostgreSQL":
235
+ case "postgresql":
224
236
  return getColumnsByTablePostgres(
225
237
  connection as Pool,
226
238
  schemaName,
227
239
  tableName
228
240
  );
229
- case "Snowflake":
241
+ case "snowflake":
230
242
  return getColumnsByTableSnowflake(
231
243
  connection as snowflake.Connection,
232
244
  schemaName,
233
245
  tableName
234
246
  );
235
- case "BigQuery":
247
+ case "bigquery":
236
248
  return getColumnsByTableBigQuery(
237
249
  connection as BigQuery,
238
250
  schemaName,
239
251
  tableName
240
252
  );
241
- case "MySQL":
253
+ case "mysql":
242
254
  return getColumnsByTableMysql(
243
255
  connection as MysqlPool,
244
256
  schemaName,
@@ -256,7 +268,7 @@ export async function getForiegnKeysByDatabase(
256
268
  tableName: string,
257
269
  primaryKey: string
258
270
  ): Promise<string[] | undefined> {
259
- switch (databaseType) {
271
+ switch (databaseType.toLowerCase()) {
260
272
  case "postgres":
261
273
  return getForeignKeysPostgres(
262
274
  connection as Pool,
@@ -264,28 +276,28 @@ export async function getForiegnKeysByDatabase(
264
276
  tableName,
265
277
  primaryKey
266
278
  );
267
- case "PostgreSQL":
279
+ case "postgresql":
268
280
  return getForeignKeysPostgres(
269
281
  connection as Pool,
270
282
  schemaName,
271
283
  tableName,
272
284
  primaryKey
273
285
  );
274
- case "Snowflake":
286
+ case "snowflake":
275
287
  return getForeignKeysSnowflake(
276
288
  connection as snowflake.Connection,
277
289
  schemaName,
278
290
  tableName,
279
291
  primaryKey
280
292
  );
281
- case "BigQuery":
293
+ case "bigquery":
282
294
  return getForeignKeysBigQuery(
283
295
  connection as BigQuery,
284
296
  schemaName,
285
297
  tableName,
286
298
  primaryKey
287
299
  );
288
- case "MySQL":
300
+ case "mysql":
289
301
  return getForeignKeysMysql(
290
302
  connection as MysqlPool,
291
303
  schemaName,
@@ -301,38 +313,38 @@ export function getColumnInfoBySchemaByDatabase(
301
313
  databaseType: DatabaseType,
302
314
  connection: DatabaseConnection,
303
315
  schemaName: string,
304
- tables: string[]
316
+ tables: string[] | { tableName: string; schemaName: string }[]
305
317
  ) {
306
- switch (databaseType) {
318
+ switch (databaseType.toLowerCase()) {
307
319
  case "postgres":
308
320
  return getSchemaColumnInfoPostgress(
309
321
  connection as Pool,
310
322
  schemaName,
311
- tables
323
+ tables as { tableName: string; schemaName: string }[]
312
324
  );
313
- case "PostgreSQL":
325
+ case "postgresql":
314
326
  return getSchemaColumnInfoPostgress(
315
327
  connection as Pool,
316
328
  schemaName,
317
- tables
329
+ tables as { tableName: string; schemaName: string }[]
318
330
  );
319
- case "Snowflake":
331
+ case "snowflake":
320
332
  return getSchemaColumnInfoSnowflake(
321
333
  connection as snowflake.Connection,
322
334
  schemaName,
323
- tables
335
+ tables as { tableName: string; schemaName: string }[]
324
336
  );
325
- case "BigQuery":
337
+ case "bigquery":
326
338
  return getSchemaColumnInfoBigQuery(
327
339
  connection as BigQuery,
328
340
  schemaName,
329
- tables
341
+ tables as { tableName: string; schemaName: string }[]
330
342
  );
331
- case "MySQL":
343
+ case "mysql":
332
344
  return getSchemaColumnInfoMysql(
333
345
  connection as MysqlPool,
334
346
  schemaName,
335
- tables
347
+ tables as { tableName: string; schemaName: string }[]
336
348
  );
337
349
  default:
338
350
  return undefined;
package/src/db/Mysql.ts CHANGED
@@ -82,11 +82,18 @@ export async function getSchemasMysql(
82
82
 
83
83
  export async function getTablesBySchemaMysql(
84
84
  connection: MysqlPool,
85
- schemaName: string
86
- ): Promise<string[]> {
87
- const sql = `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '${schemaName}'`;
88
- const results = await runQueryMysql(sql, connection);
89
- return results.rows.map((row) => row.TABLE_NAME);
85
+ schemaNames: string[]
86
+ ): Promise<{ tableName: string; schemaName: string }[]> {
87
+ const allColumns = await Promise.all(
88
+ schemaNames.map(async (schema) => {
89
+ const sql = `SELECT TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '${schema}'`;
90
+ const results = await runQueryMysql(sql, connection);
91
+ return results.rows.map((row) => {
92
+ return { tableName: row.TABLE_NAME, schemaName: row.TABLE_SCHEMA };
93
+ });
94
+ })
95
+ );
96
+ return allColumns.flat();
90
97
  }
91
98
 
92
99
  export async function getColumnsByTableMysql(
@@ -142,26 +149,26 @@ export async function getForeignKeysMysql(
142
149
  export async function getSchemaColumnInfoMysql(
143
150
  connection: MysqlPool,
144
151
  schemaName: string,
145
- tableNames: string[]
152
+ tableNames: { tableName: string; schemaName: string }[]
146
153
  ): Promise<
147
- { tableName: string; columns: { columnName: string; dataTypeId: number }[] }[]
154
+ { tableName: string; columns: { columnName: string; dataTypeID: number }[] }[]
148
155
  > {
149
156
  const allColumns = await Promise.all(
150
157
  tableNames.map(async (tableName) => {
151
158
  const query = `
152
159
  SELECT COLUMN_NAME as columnName,
153
160
  DATA_TYPE as dataType FROM INFORMATION_SCHEMA.COLUMNS
154
- WHERE TABLE_SCHEMA = '${schemaName}'
155
- AND TABLE_NAME = '${tableName}'
161
+ WHERE TABLE_SCHEMA = '${tableName.schemaName}'
162
+ AND TABLE_NAME = '${tableName.tableName}'
156
163
  `;
157
164
  const results = await runQueryMysql(query, connection);
158
165
  return {
159
- tableName,
160
- displayName: tableName,
166
+ tableName: `${tableName.schemaName}.${tableName.tableName}`,
167
+ displayName: `${tableName.schemaName}.${tableName.tableName}`,
161
168
  columns: results.rows.map((row: any) => ({
162
169
  columnName: row.columnName,
163
170
  displayName: row.columnName,
164
- dataTypeId: mysqlTextDataTypeToPostgresOID(row.dataType),
171
+ dataTypeID: mysqlTextDataTypeToPostgresOID(row.dataType),
165
172
  fieldType: row.dataType,
166
173
  })),
167
174
  };