From 120a483564b2a90a3243f30d6637ede7d04fd338 Mon Sep 17 00:00:00 2001 From: Sanket Rajendra Shinde <126979961+sanketshinde3001@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:57:41 +0530 Subject: [PATCH 1/3] Update tablesApiClient.ts --- src/tables/tablesApiClient.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tables/tablesApiClient.ts b/src/tables/tablesApiClient.ts index d82c562..48d596f 100644 --- a/src/tables/tablesApiClient.ts +++ b/src/tables/tablesApiClient.ts @@ -41,3 +41,13 @@ export default abstract class TablesApiClient { */ abstract deleteTable(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; + From ea505d758fc5eea6e733d196065b2abd00bc0c34 Mon Sep 17 00:00:00 2001 From: Sanket Rajendra Shinde <126979961+sanketshinde3001@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:58:04 +0530 Subject: [PATCH 2/3] Update tablesRestApiClient.ts --- src/tables/tablesRestApiClient.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/tables/tablesRestApiClient.ts b/src/tables/tablesRestApiClient.ts index 2b83531..66b099c 100644 --- a/src/tables/tablesRestApiClient.ts +++ b/src/tables/tablesRestApiClient.ts @@ -88,3 +88,27 @@ export default class TablesRestApiClient extends TablesApiClient { } } } + +/** + * 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); + + // Check for errors + if (sqlQueryResult.error_message) { + throw new MindsDbError(sqlQueryResult.error_message); + } +} + From 65fea857062d9dd35606e812aaa78b1d8e299185 Mon Sep 17 00:00:00 2001 From: Sanket Rajendra Shinde <126979961+sanketshinde3001@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:40:28 +0530 Subject: [PATCH 3/3] Update table.ts --- src/tables/table.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tables/table.ts b/src/tables/table.ts index a4e9c8b..9772978 100644 --- a/src/tables/table.ts +++ b/src/tables/table.ts @@ -29,7 +29,13 @@ export default class Table { this.name = name; this.integration = integration; } - + /** + * Removes this table from its integration. + * @throws {MindsDbError} - Something went wrong removing this table. + */ + async removeTable(): Promise { + await this.tablesApiClient.removeTable(this.name, this.integration); + } /** * Deletes this table from its integration. * @throws {MindsDbError} - Something went wrong deleting this table.