Refactor code structure for improved readability and maintainability
This commit is contained in:
41
src/query/executer/query.executer.service.ts
Normal file
41
src/query/executer/query.executer.service.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Query } from "../entities/query.enitity";
|
||||
import { Repository } from "typeorm";
|
||||
import { Vm } from "src/vm/vm.class";
|
||||
import { Module } from "src/vm/module.class";
|
||||
|
||||
@Injectable()
|
||||
export class QueryExecuterService {
|
||||
constructor(
|
||||
@InjectRepository(Query)
|
||||
private readonly queryRepository: Repository<Query>
|
||||
) {}
|
||||
|
||||
async runQuery(token: string, queryData: any) {
|
||||
const query = await this.queryRepository.findOne({
|
||||
where: { id: token },
|
||||
});
|
||||
|
||||
if (!query) {
|
||||
throw new Error("Query not found");
|
||||
}
|
||||
|
||||
const vm = this.createVm(query);
|
||||
|
||||
await vm.runScript(query.source);
|
||||
|
||||
// Here you would add the logic to actually execute the query
|
||||
// against your database or data source. This is a placeholder.
|
||||
return { message: "Query executed", query: queryData };
|
||||
}
|
||||
|
||||
private createVm(query: Query) {
|
||||
return new Vm({
|
||||
memoryLimit: 5,
|
||||
modules: query.modules.map((module) => {
|
||||
return new Module(module.name, module.sourcePath);
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user