mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
23 lines
717 B
TypeScript
23 lines
717 B
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
import { readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
@Injectable()
|
|
export class SqlLoaderService {
|
|
private readonly logger = new Logger(SqlLoaderService.name);
|
|
private readonly sqlRootPath = join(__dirname, '../sql/queries');
|
|
|
|
loadQuery(module: string, queryName: string, path: string): string {
|
|
const filePath = join(process.cwd(), path, module, `${queryName}.sql`);
|
|
try {
|
|
return readFileSync(filePath, 'utf8');
|
|
} catch (error) {
|
|
this.logger.error(
|
|
`Failed to load SQL query: ${module}/${queryName}`,
|
|
error.stack,
|
|
);
|
|
throw new Error(`SQL query not found: ${module}/${queryName}`);
|
|
}
|
|
}
|
|
}
|