feat: add logging functionality with LoggerService; implement log entity and controller; enhance query processing with logging support
This commit is contained in:
@ -39,6 +39,19 @@ export class DatabaseManagerController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get("tables/:databaseId")
|
||||
getTables(@Param("databaseId") databaseId: string) {
|
||||
return this.databaseManagerService.getTableList(databaseId);
|
||||
}
|
||||
|
||||
@Get("columns/:databaseId/:tableName")
|
||||
getColumns(
|
||||
@Param("databaseId") databaseId: string,
|
||||
@Param("tableName") tableName: string
|
||||
) {
|
||||
return this.databaseManagerService.getTableColumns(databaseId, tableName);
|
||||
}
|
||||
|
||||
@Get("migration/up/:databaseId")
|
||||
migrateUp(@Param("databaseId") databaseId: string) {
|
||||
return this.migrationService.up(databaseId);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { forwardRef, Inject, Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Database } from "../entities/database.entity";
|
||||
import { Repository } from "typeorm";
|
||||
@ -13,6 +13,7 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
constructor(
|
||||
@InjectRepository(Database)
|
||||
private databaseRepository: Repository<Database>,
|
||||
@Inject(forwardRef(() => ProjectService))
|
||||
private readonly projectService: ProjectService,
|
||||
private readonly databaseNodeService: DatabaseNodeService,
|
||||
@Inject(RedisClient)
|
||||
@ -146,4 +147,24 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
|
||||
return await this.databaseRepository.save(database);
|
||||
}
|
||||
|
||||
async getTableList(databaseId: string): Promise<string[]> {
|
||||
const results = await this.runQuery(
|
||||
databaseId,
|
||||
"SHOW TABLES;",
|
||||
true /* use query user */
|
||||
);
|
||||
|
||||
return results.map((row) => Object.values(row)[0]);
|
||||
}
|
||||
|
||||
async getTableColumns(databaseId: string, tableName: string): Promise<any[]> {
|
||||
const results = await this.runQuery(
|
||||
databaseId,
|
||||
`SHOW COLUMNS FROM \`${tableName}\`;`,
|
||||
true /* use query user */
|
||||
);
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user