From 5f3617ec27a9693db29af5584962b565d707e0a2 Mon Sep 17 00:00:00 2001 From: Abhilash Date: Mon, 21 Oct 2024 18:11:49 +0530 Subject: [PATCH] added delete file --- src/tables/tablesApiClient.ts | 7 +++++++ src/tables/tablesRestApiClient.ts | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/tables/tablesApiClient.ts b/src/tables/tablesApiClient.ts index d82c562..8c27ed8 100644 --- a/src/tables/tablesApiClient.ts +++ b/src/tables/tablesApiClient.ts @@ -40,4 +40,11 @@ export default abstract class TablesApiClient { * @throws {MindsDbError} - Something went wrong deleting the table. */ abstract deleteTable(name: string, integration: 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; } diff --git a/src/tables/tablesRestApiClient.ts b/src/tables/tablesRestApiClient.ts index 2b83531..27f9462 100644 --- a/src/tables/tablesRestApiClient.ts +++ b/src/tables/tablesRestApiClient.ts @@ -87,4 +87,18 @@ export default class TablesRestApiClient extends TablesApiClient { throw new MindsDbError(sqlQueryResult.error_message); } } + + /** + * 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. + */ + override async deleteFile(name: string): Promise { + const sqlQuery = `DROP TABLE files.${mysql.escapeId(name)}`; + + const sqlQueryResult = await this.sqlClient.runQuery(sqlQuery); + if (sqlQueryResult.error_message) { + throw new MindsDbError(sqlQueryResult.error_message); + } + } }