fdb2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +21 -0
- package/.editorconfig +11 -0
- package/.eslintrc.cjs +14 -0
- package/.eslintrc.json +7 -0
- package/.prettierrc.js +3 -0
- package/.tpl.env +22 -0
- package/README.md +260 -0
- package/bin/build.sh +28 -0
- package/bin/deploy.sh +8 -0
- package/bin/dev.sh +10 -0
- package/bin/docker/.env +4 -0
- package/bin/docker/dev-docker-compose.yml +43 -0
- package/bin/docker/dev.Dockerfile +24 -0
- package/bin/docker/prod-docker-compose.yml +17 -0
- package/bin/docker/prod.Dockerfile +29 -0
- package/bin/fdb2.js +142 -0
- package/data/connections.demo.json +32 -0
- package/env.d.ts +1 -0
- package/nw-build.js +120 -0
- package/nw-dev.js +65 -0
- package/package.json +114 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +9 -0
- package/public/modules/header.tpl +14 -0
- package/public/modules/initial_state.tpl +55 -0
- package/server/index.ts +677 -0
- package/server/model/connection.entity.ts +66 -0
- package/server/model/database.entity.ts +246 -0
- package/server/service/connection.service.ts +334 -0
- package/server/service/database/base.service.ts +363 -0
- package/server/service/database/database.service.ts +510 -0
- package/server/service/database/index.ts +7 -0
- package/server/service/database/mssql.service.ts +723 -0
- package/server/service/database/mysql.service.ts +761 -0
- package/server/service/database/oracle.service.ts +839 -0
- package/server/service/database/postgres.service.ts +744 -0
- package/server/service/database/sqlite.service.ts +559 -0
- package/server/service/session.service.ts +158 -0
- package/server.js +128 -0
- package/src/adapter/ajax.ts +135 -0
- package/src/assets/base.css +1 -0
- package/src/assets/database.css +950 -0
- package/src/assets/images/collapse.png +0 -0
- package/src/assets/images/no-login.png +0 -0
- package/src/assets/images/svg/illustrations/illustration-1.svg +1 -0
- package/src/assets/images/svg/illustrations/illustration-2.svg +2 -0
- package/src/assets/images/svg/illustrations/illustration-3.svg +50 -0
- package/src/assets/images/svg/illustrations/illustration-4.svg +1 -0
- package/src/assets/images/svg/illustrations/illustration-5.svg +73 -0
- package/src/assets/images/svg/illustrations/illustration-6.svg +89 -0
- package/src/assets/images/svg/illustrations/illustration-7.svg +39 -0
- package/src/assets/images/svg/illustrations/illustration-8.svg +1 -0
- package/src/assets/images/svg/separators/curve-2.svg +3 -0
- package/src/assets/images/svg/separators/curve.svg +3 -0
- package/src/assets/images/svg/separators/line.svg +3 -0
- package/src/assets/images/theme/light/screen-1-1000x800.jpg +0 -0
- package/src/assets/images/theme/light/screen-2-1000x800.jpg +0 -0
- package/src/assets/login/bg.jpg +0 -0
- package/src/assets/login/bg.png +0 -0
- package/src/assets/login/left.jpg +0 -0
- package/src/assets/logo.svg +73 -0
- package/src/assets/logo.webp +0 -0
- package/src/assets/main.css +1 -0
- package/src/base/config.ts +20 -0
- package/src/base/detect.ts +134 -0
- package/src/base/entity.ts +92 -0
- package/src/base/eventBus.ts +37 -0
- package/src/base//345/237/272/347/241/200/345/261/202.md +7 -0
- package/src/components/connection-editor/index.vue +590 -0
- package/src/components/dataGrid/index.vue +105 -0
- package/src/components/dataGrid/pagination.vue +106 -0
- package/src/components/loading/index.vue +43 -0
- package/src/components/modal/index.ts +181 -0
- package/src/components/modal/index.vue +560 -0
- package/src/components/toast/index.ts +44 -0
- package/src/components/toast/toast.vue +58 -0
- package/src/components/user/name.vue +104 -0
- package/src/components/user/selector.vue +416 -0
- package/src/domain/SysConfig.ts +74 -0
- package/src/platform/App.vue +8 -0
- package/src/platform/database/components/connection-detail.vue +1154 -0
- package/src/platform/database/components/data-editor.vue +478 -0
- package/src/platform/database/components/data-import-export.vue +1602 -0
- package/src/platform/database/components/database-detail.vue +1173 -0
- package/src/platform/database/components/database-monitor.vue +1086 -0
- package/src/platform/database/components/db-tools.vue +577 -0
- package/src/platform/database/components/query-history.vue +1349 -0
- package/src/platform/database/components/sql-executor.vue +738 -0
- package/src/platform/database/components/sql-query-editor.vue +1046 -0
- package/src/platform/database/components/table-detail.vue +1376 -0
- package/src/platform/database/components/table-editor.vue +690 -0
- package/src/platform/database/explorer.vue +1840 -0
- package/src/platform/database/index.vue +1193 -0
- package/src/platform/database/layout.vue +367 -0
- package/src/platform/database/router.ts +37 -0
- package/src/platform/database/styles/common.scss +602 -0
- package/src/platform/database/types/common.ts +445 -0
- package/src/platform/database/utils/export.ts +232 -0
- package/src/platform/database/utils/helpers.ts +437 -0
- package/src/platform/index.ts +33 -0
- package/src/platform/router.ts +41 -0
- package/src/service/base.ts +128 -0
- package/src/service/database.ts +500 -0
- package/src/service/login.ts +121 -0
- package/src/shims-vue.d.ts +7 -0
- package/src/stores/connection.ts +266 -0
- package/src/stores/session.ts +87 -0
- package/src/typings/database-types.ts +413 -0
- package/src/typings/database.ts +364 -0
- package/src/typings/global.d.ts +58 -0
- package/src/typings/pinia.d.ts +8 -0
- package/src/utils/clipboard.ts +30 -0
- package/src/utils/database-types.ts +243 -0
- package/src/utils/modal.ts +124 -0
- package/src/utils/request.ts +55 -0
- package/src/utils/sleep.ts +4 -0
- package/src/utils/toast.ts +73 -0
- package/src/utils/util.ts +171 -0
- package/src/utils/xlsx.ts +228 -0
- package/tsconfig.json +33 -0
- package/tsconfig.server.json +19 -0
- package/view/index.html +9 -0
- package/view/modules/header.tpl +14 -0
- package/view/modules/initial_state.tpl +20 -0
- package/vite.config.ts +384 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { ConnectionService } from '../connection.service';
|
|
2
|
+
import { BaseDatabaseService } from './base.service';
|
|
3
|
+
import {
|
|
4
|
+
DatabaseEntity,
|
|
5
|
+
TableEntity
|
|
6
|
+
} from '../../model/database.entity';
|
|
7
|
+
import { MySQLService } from './mysql.service';
|
|
8
|
+
import { PostgreSQLService } from './postgres.service';
|
|
9
|
+
import { SQLiteService } from './sqlite.service';
|
|
10
|
+
import { OracleService } from './oracle.service';
|
|
11
|
+
import { SQLServerService } from './mssql.service';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 数据库服务管理类
|
|
15
|
+
* 负责根据数据库类型选择相应的服务实现
|
|
16
|
+
*/
|
|
17
|
+
export class DatabaseService {
|
|
18
|
+
|
|
19
|
+
public connectionService: ConnectionService;
|
|
20
|
+
private mysqlService: MySQLService;
|
|
21
|
+
private postgreSQLService: PostgreSQLService;
|
|
22
|
+
private sqliteService: SQLiteService;
|
|
23
|
+
private oracleService: OracleService;
|
|
24
|
+
private sqlServerService: SQLServerService;
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
this.connectionService = new ConnectionService();
|
|
28
|
+
|
|
29
|
+
this.mysqlService = new MySQLService();
|
|
30
|
+
this.postgreSQLService = new PostgreSQLService();
|
|
31
|
+
this.sqliteService = new SQLiteService();
|
|
32
|
+
this.oracleService = new OracleService();
|
|
33
|
+
this.sqlServerService = new SQLServerService();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 获取数据库服务实例
|
|
38
|
+
*/
|
|
39
|
+
public getDatabaseService(type: string): BaseDatabaseService {
|
|
40
|
+
|
|
41
|
+
switch (type.toLowerCase()) {
|
|
42
|
+
case 'mysql':
|
|
43
|
+
return this.mysqlService;
|
|
44
|
+
case 'postgres':
|
|
45
|
+
case 'postgresql':
|
|
46
|
+
return this.postgreSQLService;
|
|
47
|
+
case 'sqlite':
|
|
48
|
+
return this.sqliteService;
|
|
49
|
+
case 'oracle':
|
|
50
|
+
return this.oracleService;
|
|
51
|
+
case 'mssql':
|
|
52
|
+
case 'sqlserver':
|
|
53
|
+
return this.sqlServerService;
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`不支持的数据库类型: ${type}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 获取数据库列表
|
|
61
|
+
*/
|
|
62
|
+
async getDatabases(connectionId: string): Promise<string[]> {
|
|
63
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId);
|
|
64
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
65
|
+
return databaseService.getDatabases(dataSource);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 获取数据库详细信息
|
|
70
|
+
*/
|
|
71
|
+
async getDatabaseInfo(connectionId: string, databaseName: string): Promise<DatabaseEntity> {
|
|
72
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
73
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
74
|
+
return databaseService.getDatabaseInfo(dataSource, databaseName);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 获取数据库表列表
|
|
79
|
+
*/
|
|
80
|
+
async getTables(connectionId: string, databaseName: string): Promise<TableEntity[]> {
|
|
81
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
82
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
83
|
+
return databaseService.getTables(dataSource, databaseName);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 获取表详细信息
|
|
88
|
+
*/
|
|
89
|
+
async getTableInfo(connectionId: string, databaseName: string, tableName: string): Promise<TableEntity> {
|
|
90
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
91
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
92
|
+
return databaseService.getTableInfo(dataSource, databaseName, tableName);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 获取表数据
|
|
97
|
+
*/
|
|
98
|
+
async getTableData(
|
|
99
|
+
connectionId: string,
|
|
100
|
+
databaseName: string,
|
|
101
|
+
tableName: string,
|
|
102
|
+
page: number = 1,
|
|
103
|
+
pageSize: number = 100,
|
|
104
|
+
where?: string,
|
|
105
|
+
orderBy?: string
|
|
106
|
+
): Promise<{ data: any[], total: number }> {
|
|
107
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
108
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
109
|
+
return databaseService.getTableData(dataSource, databaseName, tableName, page, pageSize, where, orderBy);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 执行SQL查询
|
|
114
|
+
*/
|
|
115
|
+
async executeQuery(connectionId: string, sql: string, databaseName?: string): Promise<any> {
|
|
116
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
117
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
118
|
+
return databaseService.executeQuery(dataSource, sql);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 获取视图列表
|
|
123
|
+
*/
|
|
124
|
+
async getViews(connectionId: string, databaseName: string): Promise<any[]> {
|
|
125
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
126
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
127
|
+
return databaseService.getViews(dataSource, databaseName);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 获取视图定义
|
|
132
|
+
*/
|
|
133
|
+
async getViewDefinition(connectionId: string, databaseName: string, viewName: string): Promise<string> {
|
|
134
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
135
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
136
|
+
return databaseService.getViewDefinition(dataSource, databaseName, viewName);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 获取存储过程列表
|
|
141
|
+
*/
|
|
142
|
+
async getProcedures(connectionId: string, databaseName: string): Promise<any[]> {
|
|
143
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
144
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
145
|
+
return databaseService.getProcedures(dataSource, databaseName);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 获取存储过程定义
|
|
150
|
+
*/
|
|
151
|
+
async getProcedureDefinition(connectionId: string, databaseName: string, procedureName: string): Promise<string> {
|
|
152
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
153
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
154
|
+
return databaseService.getProcedureDefinition(dataSource, databaseName, procedureName);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 测试数据库连接
|
|
159
|
+
*/
|
|
160
|
+
async testConnection(connectionId: string): Promise<boolean> {
|
|
161
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId);
|
|
162
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
163
|
+
return databaseService.testConnection(dataSource);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 获取支持的数据库类型
|
|
168
|
+
*/
|
|
169
|
+
getSupportedDatabaseTypes() {
|
|
170
|
+
return [
|
|
171
|
+
{
|
|
172
|
+
value: 'mysql',
|
|
173
|
+
label: 'MySQL',
|
|
174
|
+
icon: 'bi-database',
|
|
175
|
+
defaultPort: 3306,
|
|
176
|
+
description: 'MySQL数据库',
|
|
177
|
+
features: {
|
|
178
|
+
supportSchemas: false,
|
|
179
|
+
supportProcedures: true,
|
|
180
|
+
supportTriggers: true,
|
|
181
|
+
supportViews: true,
|
|
182
|
+
supportFullTextSearch: true,
|
|
183
|
+
supportJson: true
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
value: 'postgres',
|
|
188
|
+
label: 'PostgreSQL',
|
|
189
|
+
icon: 'bi-database',
|
|
190
|
+
defaultPort: 5432,
|
|
191
|
+
description: 'PostgreSQL数据库',
|
|
192
|
+
features: {
|
|
193
|
+
supportSchemas: true,
|
|
194
|
+
supportProcedures: true,
|
|
195
|
+
supportTriggers: true,
|
|
196
|
+
supportViews: true,
|
|
197
|
+
supportFullTextSearch: true,
|
|
198
|
+
supportJson: true,
|
|
199
|
+
supportArrays: true,
|
|
200
|
+
supportEnum: true
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
value: 'sqlite',
|
|
205
|
+
label: 'SQLite',
|
|
206
|
+
icon: 'bi-database',
|
|
207
|
+
defaultPort: null,
|
|
208
|
+
description: 'SQLite数据库文件',
|
|
209
|
+
features: {
|
|
210
|
+
supportSchemas: false,
|
|
211
|
+
supportProcedures: false,
|
|
212
|
+
supportTriggers: true,
|
|
213
|
+
supportViews: true,
|
|
214
|
+
supportFullTextSearch: true,
|
|
215
|
+
supportJson: false,
|
|
216
|
+
supportArrays: false
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
value: 'oracle',
|
|
221
|
+
label: 'Oracle',
|
|
222
|
+
icon: 'bi-database',
|
|
223
|
+
defaultPort: 1521,
|
|
224
|
+
description: 'Oracle数据库',
|
|
225
|
+
features: {
|
|
226
|
+
supportSchemas: true,
|
|
227
|
+
supportProcedures: true,
|
|
228
|
+
supportTriggers: true,
|
|
229
|
+
supportViews: true,
|
|
230
|
+
supportFullTextSearch: true,
|
|
231
|
+
supportJson: false,
|
|
232
|
+
supportArrays: false,
|
|
233
|
+
supportSequences: true,
|
|
234
|
+
supportSynonyms: true
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
value: 'mssql',
|
|
239
|
+
label: 'SQL Server',
|
|
240
|
+
icon: 'bi-database',
|
|
241
|
+
defaultPort: 1433,
|
|
242
|
+
description: 'Microsoft SQL Server',
|
|
243
|
+
features: {
|
|
244
|
+
supportSchemas: false,
|
|
245
|
+
supportProcedures: true,
|
|
246
|
+
supportTriggers: true,
|
|
247
|
+
supportViews: true,
|
|
248
|
+
supportFullTextSearch: true,
|
|
249
|
+
supportJson: true,
|
|
250
|
+
supportArrays: false,
|
|
251
|
+
supportStoredProcedures: true
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 创建数据库
|
|
259
|
+
*/
|
|
260
|
+
async createDatabase(connectionId: string, databaseName: string, options?: any): Promise<void> {
|
|
261
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId);
|
|
262
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
263
|
+
return databaseService.createDatabase(dataSource, databaseName, options);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 删除数据库
|
|
268
|
+
*/
|
|
269
|
+
async dropDatabase(connectionId: string, databaseName: string): Promise<void> {
|
|
270
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId);
|
|
271
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
272
|
+
return databaseService.dropDatabase(dataSource, databaseName);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 导出数据库架构
|
|
277
|
+
*/
|
|
278
|
+
async exportSchema(connectionId: string, databaseName: string): Promise<string> {
|
|
279
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
280
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
281
|
+
return databaseService.exportSchema(dataSource, databaseName);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* 查看数据库日志
|
|
286
|
+
*/
|
|
287
|
+
async viewLogs(connectionId: string, databaseName?: string, limit: number = 100): Promise<any[]> {
|
|
288
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
289
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
290
|
+
return databaseService.viewLogs(dataSource, databaseName, limit);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* 备份数据库
|
|
295
|
+
*/
|
|
296
|
+
async backupDatabase(connectionId: string, databaseName: string, options?: any): Promise<string> {
|
|
297
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
298
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
299
|
+
return databaseService.backupDatabase(dataSource, databaseName, options);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 恢复数据库
|
|
304
|
+
*/
|
|
305
|
+
async restoreDatabase(connectionId: string, databaseName: string, filePath: string, options?: any): Promise<void> {
|
|
306
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
307
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
308
|
+
return databaseService.restoreDatabase(dataSource, databaseName, filePath, options);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* 获取数据库统计信息
|
|
313
|
+
*/
|
|
314
|
+
async getDatabaseStats(connectionId: string, databaseName: string): Promise<any> {
|
|
315
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
316
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
317
|
+
|
|
318
|
+
const tables = await databaseService.getTables(dataSource, databaseName);
|
|
319
|
+
const tableCount = tables.length;
|
|
320
|
+
const size = await databaseService.getDatabaseSize(dataSource, databaseName);
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
tableCount,
|
|
324
|
+
size,
|
|
325
|
+
tables: tables.map(table => ({
|
|
326
|
+
name: table.name,
|
|
327
|
+
rowCount: table.rowCount || 0,
|
|
328
|
+
size: table.dataSize || 0
|
|
329
|
+
}))
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* 优化数据库
|
|
335
|
+
*/
|
|
336
|
+
async optimizeDatabase(connectionId: string, databaseName: string): Promise<any> {
|
|
337
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
338
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
339
|
+
|
|
340
|
+
const tables = await databaseService.getTables(dataSource, databaseName);
|
|
341
|
+
const results = [];
|
|
342
|
+
|
|
343
|
+
for (const table of tables) {
|
|
344
|
+
try {
|
|
345
|
+
const result = await dataSource.query(`OPTIMIZE TABLE \`${table.name}\``);
|
|
346
|
+
results.push({ table: table.name, success: true, result });
|
|
347
|
+
} catch (error) {
|
|
348
|
+
results.push({ table: table.name, success: false, error: error.message });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return { results };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 分析表
|
|
357
|
+
*/
|
|
358
|
+
async analyzeTables(connectionId: string, databaseName: string): Promise<any> {
|
|
359
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
360
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
361
|
+
|
|
362
|
+
const tables = await databaseService.getTables(dataSource, databaseName);
|
|
363
|
+
const results = [];
|
|
364
|
+
|
|
365
|
+
for (const table of tables) {
|
|
366
|
+
try {
|
|
367
|
+
const result = await dataSource.query(`ANALYZE TABLE \`${table.name}\``);
|
|
368
|
+
results.push({ table: table.name, success: true, result });
|
|
369
|
+
} catch (error) {
|
|
370
|
+
results.push({ table: table.name, success: false, error: error.message });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return { results };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 修复表
|
|
379
|
+
*/
|
|
380
|
+
async repairTables(connectionId: string, databaseName: string): Promise<any> {
|
|
381
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
382
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
383
|
+
|
|
384
|
+
const tables = await databaseService.getTables(dataSource, databaseName);
|
|
385
|
+
const results = [];
|
|
386
|
+
|
|
387
|
+
for (const table of tables) {
|
|
388
|
+
try {
|
|
389
|
+
const result = await dataSource.query(`REPAIR TABLE \`${table.name}\``);
|
|
390
|
+
results.push({ table: table.name, success: true, result });
|
|
391
|
+
} catch (error) {
|
|
392
|
+
results.push({ table: table.name, success: false, error: error.message });
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return { results };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* 导出表数据到 SQL 文件
|
|
401
|
+
*/
|
|
402
|
+
async exportTableDataToSQL(connectionId: string, databaseName: string, tableName: string, options?: any): Promise<string> {
|
|
403
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
404
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
405
|
+
return databaseService.exportTableDataToSQL(dataSource, databaseName, tableName, options);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 导出表数据到 CSV 文件
|
|
410
|
+
*/
|
|
411
|
+
async exportTableDataToCSV(connectionId: string, databaseName: string, tableName: string, options?: any): Promise<string> {
|
|
412
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
413
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
414
|
+
return databaseService.exportTableDataToCSV(dataSource, databaseName, tableName, options);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* 导出表数据到 JSON 文件
|
|
419
|
+
*/
|
|
420
|
+
async exportTableDataToJSON(connectionId: string, databaseName: string, tableName: string, options?: any): Promise<string> {
|
|
421
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
422
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
423
|
+
return databaseService.exportTableDataToJSON(dataSource, databaseName, tableName, options);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* 导出表数据到 Excel 文件
|
|
428
|
+
*/
|
|
429
|
+
async exportTableDataToExcel(connectionId: string, databaseName: string, tableName: string, options?: any): Promise<string> {
|
|
430
|
+
const dataSource = await this.connectionService.getActiveConnection(connectionId, databaseName);
|
|
431
|
+
const databaseService = this.getDatabaseService(dataSource.options.type as string);
|
|
432
|
+
return databaseService.exportTableDataToExcel(dataSource, databaseName, tableName, options);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* 获取数据库类型特定的配置
|
|
437
|
+
*/
|
|
438
|
+
getDatabaseTypeSpecificConfig(type: string) {
|
|
439
|
+
const service = this.getDatabaseService(type);
|
|
440
|
+
return {
|
|
441
|
+
type: service.getDatabaseType(),
|
|
442
|
+
features: this.getDatabaseFeatures(type)
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* 获取数据库特性
|
|
448
|
+
*/
|
|
449
|
+
private getDatabaseFeatures(type: string) {
|
|
450
|
+
switch (type.toLowerCase()) {
|
|
451
|
+
case 'mysql':
|
|
452
|
+
return {
|
|
453
|
+
supportSchemas: false,
|
|
454
|
+
supportProcedures: true,
|
|
455
|
+
supportTriggers: true,
|
|
456
|
+
supportViews: true,
|
|
457
|
+
supportFullTextSearch: true,
|
|
458
|
+
supportJson: true
|
|
459
|
+
};
|
|
460
|
+
case 'postgres':
|
|
461
|
+
case 'postgresql':
|
|
462
|
+
return {
|
|
463
|
+
supportSchemas: true,
|
|
464
|
+
supportProcedures: true,
|
|
465
|
+
supportTriggers: true,
|
|
466
|
+
supportViews: true,
|
|
467
|
+
supportFullTextSearch: true,
|
|
468
|
+
supportJson: true,
|
|
469
|
+
supportArrays: true,
|
|
470
|
+
supportEnum: true
|
|
471
|
+
};
|
|
472
|
+
case 'sqlite':
|
|
473
|
+
return {
|
|
474
|
+
supportSchemas: false,
|
|
475
|
+
supportProcedures: false,
|
|
476
|
+
supportTriggers: true,
|
|
477
|
+
supportViews: true,
|
|
478
|
+
supportFullTextSearch: true,
|
|
479
|
+
supportJson: false,
|
|
480
|
+
supportArrays: false
|
|
481
|
+
};
|
|
482
|
+
case 'oracle':
|
|
483
|
+
return {
|
|
484
|
+
supportSchemas: true,
|
|
485
|
+
supportProcedures: true,
|
|
486
|
+
supportTriggers: true,
|
|
487
|
+
supportViews: true,
|
|
488
|
+
supportFullTextSearch: true,
|
|
489
|
+
supportJson: false,
|
|
490
|
+
supportArrays: false,
|
|
491
|
+
supportSequences: true,
|
|
492
|
+
supportSynonyms: true
|
|
493
|
+
};
|
|
494
|
+
case 'mssql':
|
|
495
|
+
case 'sqlserver':
|
|
496
|
+
return {
|
|
497
|
+
supportSchemas: false,
|
|
498
|
+
supportProcedures: true,
|
|
499
|
+
supportTriggers: true,
|
|
500
|
+
supportViews: true,
|
|
501
|
+
supportFullTextSearch: true,
|
|
502
|
+
supportJson: true,
|
|
503
|
+
supportArrays: false,
|
|
504
|
+
supportStoredProcedures: true
|
|
505
|
+
};
|
|
506
|
+
default:
|
|
507
|
+
return {};
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BaseDatabaseService } from './base.service';
|
|
2
|
+
export { MySQLService } from './mysql.service';
|
|
3
|
+
export { PostgreSQLService } from './postgres.service';
|
|
4
|
+
export { SQLiteService } from './sqlite.service';
|
|
5
|
+
export { OracleService } from './oracle.service';
|
|
6
|
+
export { SQLServerService } from './mssql.service';
|
|
7
|
+
export { DatabaseService } from './database.service';
|