Refactor code structure for improved readability and maintainability

This commit is contained in:
lborv
2025-09-17 17:02:03 +03:00
parent afb1f343e0
commit db58d6ecb1
28 changed files with 674 additions and 132 deletions

View 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);
}),
});
}
}