2025-04-07 12:28:39 +05:30
|
|
|
import { Injectable } from '@nestjs/common';
|
2025-04-07 15:39:23 +05:30
|
|
|
import { Connection, Request } from 'mssql';
|
2025-04-07 12:28:39 +05:30
|
|
|
import { MssqlDBService } from 'src/db/db.service';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class MssqlService {
|
|
|
|
|
|
|
|
|
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
|
|
|
|
|
|
|
|
|
async checkConnection() {
|
2025-04-07 17:10:59 +05:30
|
|
|
let connection : Connection;
|
2025-04-07 12:28:39 +05:30
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.mssqlDBService.getConnection();
|
|
|
|
|
const request = new Request(connection);
|
|
|
|
|
const result = await request.query('SELECT GETDATE() AS CurrentDateTime');
|
|
|
|
|
return { data: result.recordset[0].CurrentDateTime }
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error checking connection:', error);
|
2025-04-07 17:10:59 +05:30
|
|
|
return {error:error.message}
|
2025-05-02 12:50:56 +05:30
|
|
|
}
|
2025-04-07 15:39:23 +05:30
|
|
|
}
|
|
|
|
|
|
2025-04-07 12:28:39 +05:30
|
|
|
}
|