mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 15:26:36 +08:00
db manager
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import {BaseService} from '@/lib/services';
|
||||
import type {DBOverview, ExecuteSQLResponse, TableDataResponse} from './types';
|
||||
|
||||
/**
|
||||
* 数据库管理服务类
|
||||
*/
|
||||
export class DbManageService extends BaseService {
|
||||
protected static readonly basePath = '/api/v1/admin/db-manage';
|
||||
|
||||
/**
|
||||
* 获取数据库运行概览
|
||||
*/
|
||||
static async getOverview(): Promise<DBOverview> {
|
||||
return this.get<DBOverview>('/overview');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库所有物理表名
|
||||
*/
|
||||
static async listTables(): Promise<string[]> {
|
||||
return this.get<string[]>('/tables');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某张数据表的数据(分页)
|
||||
*/
|
||||
static async getTableData(params: {
|
||||
table: string;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}): Promise<TableDataResponse> {
|
||||
return this.get<TableDataResponse>('/table-data', params as unknown as Record<string, unknown>);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在数据库中执行自定义 SQL 语句
|
||||
*/
|
||||
static async executeSQL(sql: string): Promise<ExecuteSQLResponse> {
|
||||
return this.post<ExecuteSQLResponse>('/query', { sql });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { DbManageService } from './db-manage.service';
|
||||
export type { DBOverview, TableDataResponse, ExecuteSQLResponse } from './types';
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 数据库概览信息
|
||||
*/
|
||||
export interface DBOverview {
|
||||
type: string;
|
||||
version: string;
|
||||
name: string;
|
||||
size: string;
|
||||
table_count: number;
|
||||
connections: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态数据表分页数据响应
|
||||
*/
|
||||
export interface TableDataResponse {
|
||||
columns: string[];
|
||||
total: number;
|
||||
results: Record<string, unknown>[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行自定义 SQL 的响应
|
||||
*/
|
||||
export interface ExecuteSQLResponse {
|
||||
type: "select" | "exec";
|
||||
columns?: string[];
|
||||
results?: Record<string, unknown>[];
|
||||
affected_rows: number;
|
||||
execution_time_ms: number;
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import {AdminService} from './admin';
|
||||
import {UserService} from './user';
|
||||
import {ConfigService} from './config';
|
||||
import {UploadService} from './upload';
|
||||
import {DbManageService} from './db-manage';
|
||||
|
||||
/**
|
||||
* 服务对象
|
||||
@@ -44,6 +45,8 @@ const services = {
|
||||
config: ConfigService,
|
||||
/** 上传服务 */
|
||||
upload: UploadService,
|
||||
/** 数据库管理服务 */
|
||||
dbManage: DbManageService,
|
||||
} as const;
|
||||
|
||||
export default services;
|
||||
@@ -116,3 +119,7 @@ export type { AccessToken, CreateTokenResponse } from './user';
|
||||
// 上传服务
|
||||
export { UploadService } from './upload';
|
||||
export type { UploadImageResponse } from './upload';
|
||||
|
||||
// 数据库管理服务
|
||||
export { DbManageService } from './db-manage';
|
||||
export type { DBOverview, TableDataResponse, ExecuteSQLResponse } from './db-manage';
|
||||
|
||||
Reference in New Issue
Block a user