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

fixed method declaration and implementation outside the class block #109

Merged
merged 3 commits into from
Nov 26, 2024
Merged
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
19 changes: 3 additions & 16 deletions src/tables/tablesApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export default abstract class TablesApiClient {
*/
abstract deleteTable(name: string, integration: string): Promise<void>;



/**
* Updates a table from its integration.
* @param {string} name - Name of the table to be updated.
Expand All @@ -56,7 +54,7 @@ export default abstract class TablesApiClient {
updateQuery: string
): Promise<void>;

/**
/*
* 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.
Expand All @@ -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<void>;

/**
* Deletes a file from the files integration.
* @param {string} name - Name of the file to be deleted.
Expand All @@ -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<void>;

abstract uploadFile(filePath: string, fileName: string, original_file_name?: string): Promise<void>;
}

/**
* 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<void>} - Resolves when the table is successfully removed.
* @throws {MindsDbError} - Something went wrong removing the table.
*/
abstract removeTable(name: string, integration: string): Promise<void>;

72 changes: 25 additions & 47 deletions src/tables/tablesRestApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -121,34 +121,34 @@ export default class TablesRestApiClient extends TablesApiClient {
updateQuery: string
): Promise<void> {

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<void> {
override async deleteFromTable(name: string, integration: string, select?: string): Promise<void> {
/**
If select parameter is not passed then entire data from the table is deleted.
*/
Expand All @@ -160,25 +160,27 @@ export default class TablesRestApiClient extends TablesApiClient {
throw new MindsDbError(sqlQueryResult.error_message);
}
}
/*
* Insert data into this table.
* @param {Array<Array<any>> | 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<Array<any>> | 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<void> {
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.
Expand All @@ -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.
*
Expand All @@ -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<void> {
override async uploadFile(filePath: string, fileName: string, original_file_name?: string): Promise<void> {
const formData = new FormData();

if(original_file_name)
if (original_file_name)
formData.append('original_file_name', original_file_name);

if (fs.existsSync(filePath)) {
Expand Down Expand Up @@ -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<void>} - Resolves when the table is successfully removed.
* @throws {MindsDbError} - Something went wrong removing the table.
*/
override async removeTable(
name: string,
integration: string
): Promise<void> {
// 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);
}
}