From b7ec2f3e38a9a986cb11348fb6fdd86926de2515 Mon Sep 17 00:00:00 2001 From: Md Abid Hussain Date: Tue, 19 Nov 2024 02:01:53 +0530 Subject: [PATCH 1/2] fixed method declaration and implementation outside the class block --- src/tables/tablesApiClient.ts | 37 ++++++++++--------- src/tables/tablesRestApiClient.ts | 60 ++++++++++++++++--------------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/tables/tablesApiClient.ts b/src/tables/tablesApiClient.ts index 02d684a..82b03af 100644 --- a/src/tables/tablesApiClient.ts +++ b/src/tables/tablesApiClient.ts @@ -42,27 +42,30 @@ export default abstract class TablesApiClient { abstract deleteTable(name: string, integration: string): Promise; /** - * Insert data into this table. - * @param {string} name - Name of the table to be deleted. - * @param {string} integration - Name of the integration the table to be deleted is a part of. - * @param {string} select - SELECT query to insert data from. - * @throws {MindsDbError} - Something went wrong inserting data into the table. - */ - abstract insertTable(name: string, integration: string, select: string): Promise; + * Insert data into this table. + * @param {string} name - Name of the table to be deleted. + * @param {string} integration - Name of the integration the table to be deleted is a part of. + * @param {string} select - SELECT query to insert data from. + * @throws {MindsDbError} - Something went wrong inserting data into the table. + */ + abstract insertTable( + name: string, + integration: string, + select: string + ): Promise; /** * Deletes a file from the files integration. * @param {string} name - Name of the file to be deleted. * @throws {MindsDbError} - Something went wrong deleting the file. */ abstract deleteFile(name: string): Promise; -} - -/** - * Removes a table from its integration. - * @param {string} name - Name of the table to be removed. - * @param {string} integration - Name of the integration the table belongs to. - * @returns {Promise} - Resolves when the table is successfully removed. - * @throws {MindsDbError} - Something went wrong removing the table. - */ -abstract removeTable(name: string, integration: string): Promise; + /** + * Removes a table from its integration. + * @param {string} name - Name of the table to be removed. + * @param {string} integration - Name of the integration the table belongs to. + * @returns {Promise} - Resolves when the table is successfully removed. + * @throws {MindsDbError} - Something went wrong removing the table. + */ + abstract removeTable(name: string, integration: string): Promise; +} diff --git a/src/tables/tablesRestApiClient.ts b/src/tables/tablesRestApiClient.ts index 01c49cb..b4f7779 100644 --- a/src/tables/tablesRestApiClient.ts +++ b/src/tables/tablesRestApiClient.ts @@ -89,22 +89,28 @@ export default class TablesRestApiClient extends TablesApiClient { } /** - * Insert data into this table. - * @param {Array> | string} data - A 2D array of values to insert, or a SELECT query to insert data from. - * @throws {MindsDbError} - Something went wrong inserting data into the table. - */ - override async insertTable(name: string, integration: string, select: string): Promise { + * Insert data into this table. + * @param {Array> | string} data - A 2D array of values to insert, or a SELECT query to insert data from. + * @throws {MindsDbError} - Something went wrong inserting data into the table. + */ + override async insertTable( + name: string, + integration: string, + select: string + ): Promise { try { - const sqlQuery = `INSERT INTO ${mysql.escapeId(integration)}.${mysql.escapeId(name)} (${select})`; + const sqlQuery = `INSERT INTO ${mysql.escapeId( + integration + )}.${mysql.escapeId(name)} (${select})`; const sqlQueryResult = await this.sqlClient.runQuery(sqlQuery); if (sqlQueryResult.error_message) { throw new MindsDbError(sqlQueryResult.error_message); } - } catch(error) { + } catch (error) { throw new MindsDbError(`Insert into a table failed: ${error}`); } } - + /** * Deletes a file from the files integration. * @param {string} name - Name of the file to be deleted. @@ -118,28 +124,26 @@ export default class TablesRestApiClient extends TablesApiClient { throw new MindsDbError(sqlQueryResult.error_message); } } -} -/** - * Removes a table from its integration. - * @param {string} name - Name of the table to be removed. - * @param {string} integration - Name of the integration the table belongs to. - * @returns {Promise} - Resolves when the table is successfully removed. - * @throws {MindsDbError} - Something went wrong removing the table. - */ -override async removeTable( - name: string, - integration: string -): Promise { - // Construct the SQL query to drop the table - const sqlQuery = `DROP TABLE ${mysql.escapeId(integration)}.${mysql.escapeId(name)}`; + /** + * Removes a table from its integration. + * @param {string} name - Name of the table to be removed. + * @param {string} integration - Name of the integration the table belongs to. + * @returns {Promise} - Resolves when the table is successfully removed. + * @throws {MindsDbError} - Something went wrong removing the table. + */ + override async removeTable(name: string, integration: string): Promise { + // Construct the SQL query to drop the table + const sqlQuery = `DROP TABLE ${mysql.escapeId( + integration + )}.${mysql.escapeId(name)}`; - // Execute the SQL query using the sqlClient - const sqlQueryResult = await this.sqlClient.runQuery(sqlQuery); + // Execute the SQL query using the sqlClient + const sqlQueryResult = await this.sqlClient.runQuery(sqlQuery); - // Check for errors - if (sqlQueryResult.error_message) { - throw new MindsDbError(sqlQueryResult.error_message); + // Check for errors + if (sqlQueryResult.error_message) { + throw new MindsDbError(sqlQueryResult.error_message); + } } } - From a12c9f8e99764ae5c1a61df3265ab41119831674 Mon Sep 17 00:00:00 2001 From: Md Abid Hussain <101964499+md-abid-hussain@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:39:23 +0000 Subject: [PATCH 2/2] formatted the files --- src/tables/tablesApiClient.ts | 4 ++-- src/tables/tablesRestApiClient.ts | 38 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/tables/tablesApiClient.ts b/src/tables/tablesApiClient.ts index 85e8db8..c7b260b 100644 --- a/src/tables/tablesApiClient.ts +++ b/src/tables/tablesApiClient.ts @@ -53,7 +53,7 @@ export default abstract class TablesApiClient { integration: string, updateQuery: string ): Promise; - + /* * Deletes specific row (or multiple rows) from the table present in the given integration. * @param {string} name - Name of the table from which data is to be deleted. @@ -90,5 +90,5 @@ export default abstract class TablesApiClient { * * @throws {Error} - If there is an error during the file upload process, the promise is rejected with an error message. */ - abstract uploadFile(filePath: string, fileName: string, original_file_name ?: string): Promise; + abstract uploadFile(filePath: string, fileName: string, original_file_name?: string): Promise; } diff --git a/src/tables/tablesRestApiClient.ts b/src/tables/tablesRestApiClient.ts index 950a7bd..e6a4544 100644 --- a/src/tables/tablesRestApiClient.ts +++ b/src/tables/tablesRestApiClient.ts @@ -107,7 +107,7 @@ export default class TablesRestApiClient extends TablesApiClient { } } - + /** * Updates a table from its integration. * @param {string} name - Name of the table to be updated. @@ -121,26 +121,26 @@ export default class TablesRestApiClient extends TablesApiClient { updateQuery: string ): Promise { - let keyword="SET"; + let keyword = "SET"; let setPosition = updateQuery.toUpperCase().indexOf(keyword); let result; if (setPosition !== -1) { - // Extract the substring starting just after "SET" - result = updateQuery.substring(setPosition + keyword.length).trim(); - } + // Extract the substring starting just after "SET" + result = updateQuery.substring(setPosition + keyword.length).trim(); + } // Construct the full SQL query to update the table const sqlQuery = `UPDATE ${mysql.escapeId(integration)}.${mysql.escapeId(name)} SET ${result}`; - + // Execute the SQL query using the sqlClient const sqlQueryResult = await this.sqlClient.runQuery(sqlQuery); if (sqlQueryResult.error_message) { throw new MindsDbError(sqlQueryResult.error_message); } } - - + + /* * Deletes specific row (or multiple rows) from the table present in the given integration. * @param {string} name - Name of the table from which data is to be deleted. @@ -148,7 +148,7 @@ export default class TablesRestApiClient extends TablesApiClient { * @param {string} select - select statement to specify which rows should be deleted. * @throws {MindsDbError} - Something went wrong deleting the data from the table. */ - override async deleteFromTable(name: string, integration: string,select?:string): Promise { + override async deleteFromTable(name: string, integration: string, select?: string): Promise { /** If select parameter is not passed then entire data from the table is deleted. */ @@ -160,13 +160,13 @@ export default class TablesRestApiClient extends TablesApiClient { throw new MindsDbError(sqlQueryResult.error_message); } } - - - /* - * Insert data into this table. - * @param {Array> | string} data - A 2D array of values to insert, or a SELECT query to insert data from. - * @throws {MindsDbError} - Something went wrong inserting data into the table. - */ + + + /* + * Insert data into this table. + * @param {Array> | string} data - A 2D array of values to insert, or a SELECT query to insert data from. + * @throws {MindsDbError} - Something went wrong inserting data into the table. + */ override async insertTable(name: string, integration: string, select: string): Promise { try { const sqlQuery = `INSERT INTO ${mysql.escapeId( @@ -202,7 +202,7 @@ export default class TablesRestApiClient extends TablesApiClient { const filesUrl = new URL(Constants.FILES_URI, baseUrl); return filesUrl.toString(); } - + /** * Uploads a file asynchronously to a specified location. * @@ -220,10 +220,10 @@ export default class TablesRestApiClient extends TablesApiClient { * * @throws {Error} If there is an issue with the upload, such as network errors, permission issues, or invalid file paths. */ - override async uploadFile(filePath: string, fileName: string, original_file_name ?: string): Promise { + override async uploadFile(filePath: string, fileName: string, original_file_name?: string): Promise { const formData = new FormData(); - if(original_file_name) + if (original_file_name) formData.append('original_file_name', original_file_name); if (fs.existsSync(filePath)) {