diff --git a/src/tables/tablesApiClient.ts b/src/tables/tablesApiClient.ts index 6e0056d..c7b260b 100644 --- a/src/tables/tablesApiClient.ts +++ b/src/tables/tablesApiClient.ts @@ -41,8 +41,6 @@ export default abstract class TablesApiClient { */ abstract deleteTable(name: string, integration: string): Promise; - - /** * Updates a table from its integration. * @param {string} name - Name of the table to be updated. @@ -56,7 +54,7 @@ export default abstract class TablesApiClient { 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. * @param {string} integration - Name of the integration the table is a part of. @@ -73,7 +71,7 @@ export default abstract class TablesApiClient { * @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. @@ -92,16 +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; } - -/** - * 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 bae473e..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,34 +121,34 @@ 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. * @param {string} integration - Name of the integration the table is a part of. * @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,25 +160,27 @@ 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(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. @@ -200,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. * @@ -218,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)) { @@ -256,27 +258,3 @@ 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); - } -} -