Skip to content

Commit

Permalink
Merge branch 'mindsdb:main' into kb
Browse files Browse the repository at this point in the history
  • Loading branch information
md-abid-hussain authored Nov 13, 2024
2 parents 732197b + d7e7dbe commit 221f7b8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/jobs/jobsApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ export default abstract class JobsApiClient {
* @throws {MindsDbError} - Something went wrong while dropping the job.
*/
abstract dropJob(name: string, project: string): Promise<void>;

/**
* Lists all jobs from MindsDB.
* @param {string} name - Name of the job.
* @param {string} project - Project the job belongs to.
* @returns {Promise<void>} - Resolves after all the jobs are listed.
* @throws {MindsDbError} - Something went wrong while listing the job.
*/
abstract list(name?: string, project?: string): Promise<Array<Job>>;
}
56 changes: 56 additions & 0 deletions src/jobs/jobsRestApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,60 @@ export default class JobsRestApiClient extends JobsApiClient {
throw new MindsDbError(sqlQueryResult.error_message);
}
}

/**
* Retrieves a list of jobs from the information schema.
*
* This asynchronous method queries the database for jobs, optionally filtering
* by project name and/or job name. If both parameters are provided, the method
* combines the filters to return a more specific list of jobs.
*
* @param {string} [name] - The optional name of the job to filter the results.
* If provided, only jobs matching this name will be included.
* @param {string} [project] - The optional project name to filter the results.
* If provided, only jobs associated with this project will be included.
*
* @returns {Promise<Array<Job>>} - A promise that resolves to an array of Job objects
* representing the jobs retrieved from the database.
*
* @throws {MindsDbError} - Throws an error if the SQL query execution fails,
* containing the error message returned from the database.
*
* @example
* const jobs = await list('myJob', 'myProject');
* console.log(jobs);
*/
override async list(name?: string, project?: string): Promise<Array<Job>> {
const selectClause = `SELECT * FROM information_schema.jobs`;
let projectClause = '';
let nameClause = '';
if(project){
projectClause = `WHERE project = ${mysql.escape(project)}`;
}

if(name){
nameClause = `name = ${mysql.escape(name)}`;
}

const listJobsQuery = [selectClause, projectClause, nameClause].join(
'\n'
);

const sqlQueryResult = await this.sqlClient.runQuery(listJobsQuery);
if (sqlQueryResult.error_message) {
throw new MindsDbError(sqlQueryResult.error_message);
}
return sqlQueryResult.rows.map(
(row) => {
const job = new Job(this, row['NAME'], row['PROJECT']);
job.setEnd(row['END_AT']);
job.setEvery(row['SCHEDULE_STR']);
job.setStart(row['START_AT']);
job.setIfCondition(row['IF_QUERY']);
job.addQuery(row['QUERY']);
return job;
}
);
}

}
8 changes: 8 additions & 0 deletions src/ml_engines/ml_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export default class MLEngine {
this.connection_data = connection_data;
}

/**
* Lists all mlEngines for the user.
* @returns {Promise<Array<MLEngine>>} - List of all mlEngines.
*/
async list(): Promise<Array<MLEngine>> {
return this.mlEnginesApiClient.getAllMLEngines();
}

/**
* Removes a specified mlEngine by its name.
* @param {string} mlEngineName - The name of the mlEngine to remove.
Expand Down
8 changes: 8 additions & 0 deletions src/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ class Model {
);
}

/**
* Lists all models in the project.
* @returns {Array<Model>} - All models in the project.
*/
listModels(): Promise<Array<Model>> {
return this.modelsApiClient.getAllModels(this.project);
}

/**
* Describes an attribute of this model.
* @param {string} attribute - The attribute to describe.
Expand Down

0 comments on commit 221f7b8

Please sign in to comment.