Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a function to update a table #58 #66

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/tables/tablesApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ export default abstract class TablesApiClient {
*/
abstract deleteTable(name: string, integration: string): Promise<void>;
}

/**
* Updates a table in an integration.
* @param {string} name - Name of the table to be updated.
* @param {string} integration - Name of the integration the table belongs to.
* @param {string} updateQuery - The SQL UPDATE query to run for updating the table.
* @returns {Promise<void>} - Resolves when the table is updated.
* @throws {MindsDbError} - Something went wrong updating the table.
*/
abstract updateTable(
name: string,
integration: string,
updateQuery: string
): Promise<void>;
25 changes: 25 additions & 0 deletions src/tables/tablesRestApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,28 @@ export default class TablesRestApiClient extends TablesApiClient {
}
}
}

/**
* Updates a table in an integration.
* @param {string} name - Name of the table to be updated.
* @param {string} integration - Name of the integration the table belongs to.
* @param {string} updateQuery - The SQL UPDATE query to run for updating the table.
* @returns {Promise<void>} - Resolves when the table is updated.
* @throws {MindsDbError} - Something went wrong updating the table.
*/
override async updateTable(
name: string,
integration: string,
updateQuery: string
): Promise<void> {
// Construct the full SQL query to update the table
const sqlQuery = `UPDATE ${mysql.escapeId(integration)}.${mysql.escapeId(name)} SET ${updateQuery}`;

// 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);
}
}