feat: enhance QueryPlugin run method with error handling and update logging in Vm class

This commit is contained in:
Boris D
2025-10-09 12:57:32 +03:00
parent dac008366a
commit f357bc5e61
3 changed files with 26 additions and 4 deletions

View File

@ -15,8 +15,30 @@ export class QueryPlugin extends Plugin {
return new QueryPlugin("query", query, queryExecuterService); return new QueryPlugin("query", query, queryExecuterService);
} }
async run(data): Promise<any> { async run(data: {
return await this.QueryExecuterService.runQuery(this.query.id, data); token: string;
queryData: any;
headers?: Record<string, any>;
}): Promise<any> {
const query = await this.QueryExecuterService.queryRepository.findOne({
where: { id: this.query.id },
});
if (!query) {
throw new Error(`Query with id ${this.query.id} not found`);
}
if (query.isCommand && !this.query.isCommand) {
throw new Error(
`Query with id ${this.query.id} is a command and cannot be called from query`
);
}
return await this.QueryExecuterService.runQuery(
query.id,
data.queryData,
data.headers
);
} }
onFinish() { onFinish() {

View File

@ -85,7 +85,7 @@ export class Vm {
}); });
this.setFunction("returnResult", (res) => { this.setFunction("returnResult", (res) => {
console.log("Returning result from VM:", res); // console.log("Returning result from VM:", res);
resolvePromise(res); resolvePromise(res);
}); });

View File

@ -17,7 +17,7 @@ async function main(input, headers) {
const res = await db.execute(sql); const res = await db.execute(sql);
log(res); // log(res);
return { return {
response: { response: {