fdb2 1.0.7 → 1.0.9
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 -21
- package/.editorconfig +11 -11
- package/.eslintrc.cjs +14 -14
- package/.eslintrc.json +7 -7
- package/.prettierrc.js +3 -3
- package/.tpl.env +21 -21
- package/.vscodeignore +45 -45
- package/README.md +312 -312
- package/bin/build.sh +28 -28
- package/bin/deploy.sh +8 -8
- package/bin/dev.sh +10 -10
- package/bin/docker/dev-docker-compose.yml +43 -43
- package/bin/docker/dev.Dockerfile +24 -24
- package/bin/docker/prod-docker-compose.yml +17 -17
- package/bin/docker/prod.Dockerfile +29 -29
- package/bin/fdb2.js +220 -220
- package/dist/package.json +29 -29
- package/dist/pnpm-lock.yaml +1042 -354
- package/dist/public/explorer.css +1464 -1437
- package/dist/public/explorer.js +764 -226
- package/dist/public/index.css +1026 -1026
- package/dist/public/index.js +15 -9
- package/dist/public/layout.css +221 -221
- package/dist/public/layout.js +1 -1
- package/dist/public/vue.js +8 -2
- package/dist/scripts/preinstall.js +112 -112
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.ts +680 -671
- package/dist/server/model/connection.entity.ts +65 -65
- package/dist/server/model/database.entity.ts +245 -245
- package/dist/server/service/connection.service.d.ts +6 -1
- package/dist/server/service/connection.service.d.ts.map +1 -1
- package/dist/server/service/connection.service.js +15 -0
- package/dist/server/service/connection.service.js.map +1 -1
- package/dist/server/service/connection.service.ts +356 -341
- package/dist/server/service/database/base.service.d.ts +27 -0
- package/dist/server/service/database/base.service.d.ts.map +1 -1
- package/dist/server/service/database/base.service.js +17 -0
- package/dist/server/service/database/base.service.js.map +1 -1
- package/dist/server/service/database/base.service.ts +406 -367
- package/dist/server/service/database/cockroachdb.service.d.ts +16 -0
- package/dist/server/service/database/cockroachdb.service.d.ts.map +1 -1
- package/dist/server/service/database/cockroachdb.service.js +220 -154
- package/dist/server/service/database/cockroachdb.service.js.map +1 -1
- package/dist/server/service/database/cockroachdb.service.ts +871 -782
- package/dist/server/service/database/database.service.d.ts +4 -0
- package/dist/server/service/database/database.service.d.ts.map +1 -1
- package/dist/server/service/database/database.service.js +123 -0
- package/dist/server/service/database/database.service.js.map +1 -1
- package/dist/server/service/database/database.service.ts +775 -638
- package/dist/server/service/database/index.ts +6 -6
- package/dist/server/service/database/mongodb.service.d.ts +16 -0
- package/dist/server/service/database/mongodb.service.d.ts.map +1 -1
- package/dist/server/service/database/mongodb.service.js +35 -0
- package/dist/server/service/database/mongodb.service.js.map +1 -1
- package/dist/server/service/database/mongodb.service.ts +39 -1
- package/dist/server/service/database/mssql.service.d.ts +16 -0
- package/dist/server/service/database/mssql.service.d.ts.map +1 -1
- package/dist/server/service/database/mssql.service.js +168 -96
- package/dist/server/service/database/mssql.service.js.map +1 -1
- package/dist/server/service/database/mssql.service.ts +931 -840
- package/dist/server/service/database/mysql.service.d.ts +16 -0
- package/dist/server/service/database/mysql.service.d.ts.map +1 -1
- package/dist/server/service/database/mysql.service.js +189 -80
- package/dist/server/service/database/mysql.service.js.map +1 -1
- package/dist/server/service/database/mysql.service.ts +1025 -890
- package/dist/server/service/database/oracle.service.d.ts +16 -0
- package/dist/server/service/database/oracle.service.d.ts.map +1 -1
- package/dist/server/service/database/oracle.service.js +182 -120
- package/dist/server/service/database/oracle.service.js.map +1 -1
- package/dist/server/service/database/oracle.service.ts +1035 -959
- package/dist/server/service/database/postgres.service.d.ts +16 -0
- package/dist/server/service/database/postgres.service.d.ts.map +1 -1
- package/dist/server/service/database/postgres.service.js +154 -88
- package/dist/server/service/database/postgres.service.js.map +1 -1
- package/dist/server/service/database/postgres.service.ts +960 -871
- package/dist/server/service/database/sap.service.d.ts +16 -0
- package/dist/server/service/database/sap.service.d.ts.map +1 -1
- package/dist/server/service/database/sap.service.js +66 -0
- package/dist/server/service/database/sap.service.js.map +1 -1
- package/dist/server/service/database/sap.service.ts +89 -0
- package/dist/server/service/database/sqlite.service.d.ts +16 -0
- package/dist/server/service/database/sqlite.service.d.ts.map +1 -1
- package/dist/server/service/database/sqlite.service.js +77 -18
- package/dist/server/service/database/sqlite.service.js.map +1 -1
- package/dist/server/service/database/sqlite.service.ts +787 -708
- package/dist/server/service/session.service.ts +158 -158
- package/dist/view/index.html +38 -38
- package/env.d.ts +1 -1
- package/package.json +1 -1
- package/packages/vscode/.vscodeignore +44 -44
- package/packages/vscode/README.md +62 -62
- package/packages/vscode/out/database-services/cockroachdb.service.js +154 -154
- package/packages/vscode/out/database-services/mssql.service.js +96 -96
- package/packages/vscode/out/database-services/mysql.service.js +80 -80
- package/packages/vscode/out/database-services/oracle.service.js +120 -120
- package/packages/vscode/out/database-services/postgres.service.js +88 -88
- package/packages/vscode/out/database-services/sqlite.service.js +18 -18
- package/packages/vscode/out/provider/WebViewProvider.js +32 -32
- package/packages/vscode/package.json +142 -142
- package/packages/vscode/resources/icon.svg +5 -5
- package/packages/vscode/resources/webview/connection.css +41 -41
- package/packages/vscode/resources/webview/database.css +163 -163
- package/packages/vscode/resources/webview/index.html +9 -9
- package/packages/vscode/resources/webview/modules/header.tpl +13 -13
- package/packages/vscode/resources/webview/modules/initial_state.tpl +54 -54
- package/packages/vscode/resources/webview/query.css +104 -104
- package/packages/vscode/src/database-services/base.service.ts +362 -362
- package/packages/vscode/src/database-services/cockroachdb.service.ts +659 -659
- package/packages/vscode/src/database-services/connection.service.ts +340 -340
- package/packages/vscode/src/database-services/database.service.ts +629 -629
- package/packages/vscode/src/database-services/index.ts +6 -6
- package/packages/vscode/src/database-services/model/connection.entity.ts +65 -65
- package/packages/vscode/src/database-services/model/database.entity.ts +245 -245
- package/packages/vscode/src/database-services/mssql.service.ts +722 -722
- package/packages/vscode/src/database-services/mysql.service.ts +760 -760
- package/packages/vscode/src/database-services/oracle.service.ts +831 -831
- package/packages/vscode/src/database-services/postgres.service.ts +740 -740
- package/packages/vscode/src/database-services/sqlite.service.ts +558 -558
- package/packages/vscode/src/extension.ts +76 -76
- package/packages/vscode/src/provider/DatabaseTreeProvider.ts +167 -167
- package/packages/vscode/src/provider/WebViewProvider.ts +277 -277
- package/packages/vscode/src/service/DatabaseServiceBridge.ts +414 -414
- package/packages/vscode/src/typings/connection.ts +90 -90
- package/packages/vscode/tsconfig.json +21 -21
- package/public/index.html +9 -9
- package/public/modules/header.tpl +13 -13
- package/public/modules/initial_state.tpl +54 -54
- package/scripts/preinstall.js +112 -112
- package/server/index.ts +680 -671
- package/server/model/connection.entity.ts +65 -65
- package/server/model/database.entity.ts +245 -245
- package/server/service/connection.service.ts +356 -341
- package/server/service/database/base.service.ts +406 -367
- package/server/service/database/cockroachdb.service.ts +871 -782
- package/server/service/database/database.service.ts +775 -638
- package/server/service/database/index.ts +6 -6
- package/server/service/database/mongodb.service.ts +39 -1
- package/server/service/database/mssql.service.ts +931 -840
- package/server/service/database/mysql.service.ts +1025 -890
- package/server/service/database/oracle.service.ts +1035 -959
- package/server/service/database/postgres.service.ts +960 -871
- package/server/service/database/sap.service.ts +89 -0
- package/server/service/database/sqlite.service.ts +787 -708
- package/server/service/session.service.ts +158 -158
- package/server/tsconfig.json +20 -20
- package/server.js +149 -149
- package/server.pid +1 -0
- package/src/adapter/ajax.ts +135 -135
- package/src/assets/base.css +1 -1
- package/src/assets/database.css +949 -949
- package/src/assets/images/svg/illustrations/illustration-1.svg +1 -1
- package/src/assets/images/svg/illustrations/illustration-2.svg +2 -2
- package/src/assets/images/svg/illustrations/illustration-3.svg +50 -50
- package/src/assets/images/svg/illustrations/illustration-4.svg +1 -1
- package/src/assets/images/svg/illustrations/illustration-5.svg +73 -73
- package/src/assets/images/svg/illustrations/illustration-6.svg +89 -89
- package/src/assets/images/svg/illustrations/illustration-7.svg +39 -39
- package/src/assets/images/svg/separators/curve-2.svg +3 -3
- package/src/assets/images/svg/separators/curve.svg +3 -3
- package/src/assets/images/svg/separators/line.svg +3 -3
- package/src/assets/logo.svg +73 -73
- package/src/assets/main.css +1 -1
- package/src/base/config.ts +20 -20
- package/src/base/detect.ts +134 -134
- package/src/base/entity.ts +92 -92
- package/src/base/eventBus.ts +36 -36
- package/src/components/connection-editor/index.vue +588 -588
- package/src/components/dataGrid/index.vue +104 -104
- package/src/components/dataGrid/pagination.vue +105 -105
- package/src/components/loading/index.vue +42 -42
- package/src/components/modal/index.ts +180 -180
- package/src/components/modal/index.vue +560 -560
- package/src/components/toast/index.ts +43 -43
- package/src/components/toast/toast.vue +57 -57
- package/src/components/user/name.vue +103 -103
- package/src/components/user/selector.vue +416 -416
- package/src/domain/SysConfig.ts +74 -74
- package/src/platform/App.vue +7 -7
- package/src/platform/database/components/connection-detail.vue +1153 -1154
- package/src/platform/database/components/data-editor.vue +477 -477
- package/src/platform/database/components/database-detail.vue +1173 -1172
- package/src/platform/database/components/database-monitor.vue +1085 -1085
- package/src/platform/database/components/db-tools.vue +1264 -816
- package/src/platform/database/components/query-history.vue +1348 -1348
- package/src/platform/database/components/sql-executor.vue +737 -737
- package/src/platform/database/components/sql-query-editor.vue +1045 -1045
- package/src/platform/database/components/table-detail.vue +1375 -1376
- package/src/platform/database/components/table-editor.vue +916 -916
- package/src/platform/database/explorer.vue +1839 -1839
- package/src/platform/database/index.vue +1192 -1192
- package/src/platform/database/layout.vue +366 -366
- package/src/platform/database/router.ts +36 -36
- package/src/platform/database/styles/common.scss +601 -601
- package/src/platform/database/types/common.ts +444 -444
- package/src/platform/database/utils/export.ts +231 -231
- package/src/platform/database/utils/helpers.ts +436 -436
- package/src/platform/index.ts +32 -32
- package/src/platform/router.ts +40 -40
- package/src/platform/vscode/bridge.ts +121 -121
- package/src/platform/vscode/components/ConnectionPanel.vue +272 -272
- package/src/platform/vscode/components/DatabasePanel.vue +532 -532
- package/src/platform/vscode/components/QueryPanel.vue +371 -371
- package/src/platform/vscode/entry/connection.ts +13 -13
- package/src/platform/vscode/entry/database.ts +13 -13
- package/src/platform/vscode/entry/query.ts +13 -13
- package/src/platform/vscode/index.ts +5 -5
- package/src/service/base.ts +133 -127
- package/src/service/database.ts +505 -495
- package/src/service/login.ts +120 -120
- package/src/shims-vue.d.ts +6 -6
- package/src/stores/connection.ts +266 -266
- package/src/stores/session.ts +87 -87
- package/src/typings/database-types.ts +412 -412
- package/src/typings/database.ts +363 -363
- package/src/typings/global.d.ts +58 -58
- package/src/typings/pinia.d.ts +7 -7
- package/src/utils/clipboard.ts +29 -29
- package/src/utils/database-types.ts +242 -242
- package/src/utils/modal.ts +123 -123
- package/src/utils/request.ts +55 -55
- package/src/utils/sleep.ts +3 -3
- package/src/utils/toast.ts +73 -73
- package/src/utils/util.ts +171 -171
- package/src/utils/xlsx.ts +228 -228
- package/tsconfig.json +33 -33
- package/view/index.html +9 -9
- package/view/modules/header.tpl +13 -13
- package/view/modules/initial_state.tpl +19 -19
- package/vite.config.ts +424 -424
- package/vite.config.vscode.ts +47 -47
- package/server/backups/db_ai_breakout_2026-03-11T08-38-48-677Z.sql +0 -0
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import * as vscode from 'vscode';
|
|
2
|
-
import { DatabaseTreeProvider } from './provider/DatabaseTreeProvider';
|
|
3
|
-
import { WebViewProvider } from './provider/WebViewProvider';
|
|
4
|
-
import { getDatabaseServiceBridge } from './service/DatabaseServiceBridge';
|
|
5
|
-
|
|
6
|
-
export async function activate(context: vscode.ExtensionContext) {
|
|
7
|
-
console.log('fdb2 extension is now active!');
|
|
8
|
-
|
|
9
|
-
// 初始化数据库服务桥接
|
|
10
|
-
const dbBridge = getDatabaseServiceBridge();
|
|
11
|
-
await dbBridge.init();
|
|
12
|
-
|
|
13
|
-
// 注册侧边栏树形视图
|
|
14
|
-
const databaseProvider = new DatabaseTreeProvider(context, dbBridge);
|
|
15
|
-
vscode.window.registerTreeDataProvider(
|
|
16
|
-
'databaseExplorer',
|
|
17
|
-
databaseProvider
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
// 注册 WebView 提供者
|
|
21
|
-
const webViewProvider = new WebViewProvider(context, dbBridge);
|
|
22
|
-
|
|
23
|
-
// 注册命令
|
|
24
|
-
const commands = [
|
|
25
|
-
// 查询面板
|
|
26
|
-
vscode.commands.registerCommand('fdb2.openQueryPanel', async () => {
|
|
27
|
-
await webViewProvider.showQueryPanel();
|
|
28
|
-
}),
|
|
29
|
-
|
|
30
|
-
// 数据库管理面板
|
|
31
|
-
vscode.commands.registerCommand('fdb2.openDatabasePanel', async (connection?: any) => {
|
|
32
|
-
await webViewProvider.showDatabasePanel(connection);
|
|
33
|
-
}),
|
|
34
|
-
|
|
35
|
-
// 刷新连接
|
|
36
|
-
vscode.commands.registerCommand('fdb2.refreshConnections', () => {
|
|
37
|
-
databaseProvider.refresh();
|
|
38
|
-
}),
|
|
39
|
-
|
|
40
|
-
// 添加连接
|
|
41
|
-
vscode.commands.registerCommand('fdb2.addConnection', async () => {
|
|
42
|
-
await webViewProvider.showAddConnectionPanel();
|
|
43
|
-
databaseProvider.refresh();
|
|
44
|
-
}),
|
|
45
|
-
|
|
46
|
-
// 删除连接
|
|
47
|
-
vscode.commands.registerCommand('fdb2.deleteConnection', async (connection: any) => {
|
|
48
|
-
const confirmed = await vscode.window.showWarningMessage(
|
|
49
|
-
`确定要删除连接 "${connection.label}" 吗?`,
|
|
50
|
-
{ modal: true },
|
|
51
|
-
'删除'
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
if (confirmed === '删除') {
|
|
55
|
-
await dbBridge.connection.deleteConnection(connection.id);
|
|
56
|
-
vscode.window.showInformationMessage(`连接 "${connection.label}" 已删除`);
|
|
57
|
-
databaseProvider.refresh();
|
|
58
|
-
}
|
|
59
|
-
}),
|
|
60
|
-
|
|
61
|
-
// 编辑连接
|
|
62
|
-
vscode.commands.registerCommand('fdb2.editConnection', async (connection: any) => {
|
|
63
|
-
await webViewProvider.showEditConnectionPanel(connection);
|
|
64
|
-
databaseProvider.refresh();
|
|
65
|
-
})
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
commands.forEach(cmd => context.subscriptions.push(cmd));
|
|
69
|
-
|
|
70
|
-
// 刷新树形视图
|
|
71
|
-
databaseProvider.refresh();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function deactivate() {
|
|
75
|
-
console.log('fdb2 extension is now deactivated');
|
|
76
|
-
}
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
import { DatabaseTreeProvider } from './provider/DatabaseTreeProvider';
|
|
3
|
+
import { WebViewProvider } from './provider/WebViewProvider';
|
|
4
|
+
import { getDatabaseServiceBridge } from './service/DatabaseServiceBridge';
|
|
5
|
+
|
|
6
|
+
export async function activate(context: vscode.ExtensionContext) {
|
|
7
|
+
console.log('fdb2 extension is now active!');
|
|
8
|
+
|
|
9
|
+
// 初始化数据库服务桥接
|
|
10
|
+
const dbBridge = getDatabaseServiceBridge();
|
|
11
|
+
await dbBridge.init();
|
|
12
|
+
|
|
13
|
+
// 注册侧边栏树形视图
|
|
14
|
+
const databaseProvider = new DatabaseTreeProvider(context, dbBridge);
|
|
15
|
+
vscode.window.registerTreeDataProvider(
|
|
16
|
+
'databaseExplorer',
|
|
17
|
+
databaseProvider
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// 注册 WebView 提供者
|
|
21
|
+
const webViewProvider = new WebViewProvider(context, dbBridge);
|
|
22
|
+
|
|
23
|
+
// 注册命令
|
|
24
|
+
const commands = [
|
|
25
|
+
// 查询面板
|
|
26
|
+
vscode.commands.registerCommand('fdb2.openQueryPanel', async () => {
|
|
27
|
+
await webViewProvider.showQueryPanel();
|
|
28
|
+
}),
|
|
29
|
+
|
|
30
|
+
// 数据库管理面板
|
|
31
|
+
vscode.commands.registerCommand('fdb2.openDatabasePanel', async (connection?: any) => {
|
|
32
|
+
await webViewProvider.showDatabasePanel(connection);
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
// 刷新连接
|
|
36
|
+
vscode.commands.registerCommand('fdb2.refreshConnections', () => {
|
|
37
|
+
databaseProvider.refresh();
|
|
38
|
+
}),
|
|
39
|
+
|
|
40
|
+
// 添加连接
|
|
41
|
+
vscode.commands.registerCommand('fdb2.addConnection', async () => {
|
|
42
|
+
await webViewProvider.showAddConnectionPanel();
|
|
43
|
+
databaseProvider.refresh();
|
|
44
|
+
}),
|
|
45
|
+
|
|
46
|
+
// 删除连接
|
|
47
|
+
vscode.commands.registerCommand('fdb2.deleteConnection', async (connection: any) => {
|
|
48
|
+
const confirmed = await vscode.window.showWarningMessage(
|
|
49
|
+
`确定要删除连接 "${connection.label}" 吗?`,
|
|
50
|
+
{ modal: true },
|
|
51
|
+
'删除'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (confirmed === '删除') {
|
|
55
|
+
await dbBridge.connection.deleteConnection(connection.id);
|
|
56
|
+
vscode.window.showInformationMessage(`连接 "${connection.label}" 已删除`);
|
|
57
|
+
databaseProvider.refresh();
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
|
|
61
|
+
// 编辑连接
|
|
62
|
+
vscode.commands.registerCommand('fdb2.editConnection', async (connection: any) => {
|
|
63
|
+
await webViewProvider.showEditConnectionPanel(connection);
|
|
64
|
+
databaseProvider.refresh();
|
|
65
|
+
})
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
commands.forEach(cmd => context.subscriptions.push(cmd));
|
|
69
|
+
|
|
70
|
+
// 刷新树形视图
|
|
71
|
+
databaseProvider.refresh();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function deactivate() {
|
|
75
|
+
console.log('fdb2 extension is now deactivated');
|
|
76
|
+
}
|
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
import * as vscode from 'vscode';
|
|
2
|
-
import { DatabaseServiceBridge } from '../service/DatabaseServiceBridge';
|
|
3
|
-
import { DatabaseConnection, DatabaseInfo, TableInfo } from '../typings/connection';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 树形视图项目类型
|
|
7
|
-
*/
|
|
8
|
-
type TreeItemContext =
|
|
9
|
-
| 'connection' // 数据库连接
|
|
10
|
-
| 'database' // 数据库
|
|
11
|
-
| 'table' // 表
|
|
12
|
-
| 'view' // 视图
|
|
13
|
-
| 'table-actions'; // 表操作
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 树形视图项目
|
|
17
|
-
*/
|
|
18
|
-
class DatabaseItem extends vscode.TreeItem {
|
|
19
|
-
constructor(
|
|
20
|
-
public readonly label: string,
|
|
21
|
-
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
|
|
22
|
-
public readonly contextValue: TreeItemContext,
|
|
23
|
-
public readonly connection?: DatabaseConnection,
|
|
24
|
-
public readonly database?: DatabaseInfo,
|
|
25
|
-
public readonly table?: TableInfo
|
|
26
|
-
) {
|
|
27
|
-
super(label, collapsibleState);
|
|
28
|
-
|
|
29
|
-
// 设置图标
|
|
30
|
-
this.iconPath = this.getIconPath(contextValue);
|
|
31
|
-
|
|
32
|
-
// 设置描述
|
|
33
|
-
if (contextValue === 'connection' && connection) {
|
|
34
|
-
this.description = `${connection.host}:${connection.port}`;
|
|
35
|
-
} else if (contextValue === 'table' && table) {
|
|
36
|
-
this.description = table.type;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private getIconPath(contextValue: TreeItemContext): vscode.ThemeIcon {
|
|
41
|
-
switch (contextValue) {
|
|
42
|
-
case 'connection':
|
|
43
|
-
return new vscode.ThemeIcon('database');
|
|
44
|
-
case 'database':
|
|
45
|
-
return new vscode.ThemeIcon('server');
|
|
46
|
-
case 'table':
|
|
47
|
-
return new vscode.ThemeIcon('table');
|
|
48
|
-
case 'view':
|
|
49
|
-
return new vscode.ThemeIcon('preview');
|
|
50
|
-
case 'table-actions':
|
|
51
|
-
return new vscode.ThemeIcon('ellipsis');
|
|
52
|
-
default:
|
|
53
|
-
return new vscode.ThemeIcon('circle-outline');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 数据库树形视图提供者
|
|
60
|
-
* 提供侧边栏的数据库连接和结构树
|
|
61
|
-
*/
|
|
62
|
-
export class DatabaseTreeProvider implements vscode.TreeDataProvider<DatabaseItem> {
|
|
63
|
-
private _onDidChangeTreeData = new vscode.EventEmitter<DatabaseItem | undefined>();
|
|
64
|
-
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
|
|
65
|
-
|
|
66
|
-
constructor(
|
|
67
|
-
private context: vscode.ExtensionContext,
|
|
68
|
-
private dbBridge: DatabaseServiceBridge
|
|
69
|
-
) {}
|
|
70
|
-
|
|
71
|
-
refresh(): void {
|
|
72
|
-
this._onDidChangeTreeData.fire(undefined);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getTreeItem(element: DatabaseItem): vscode.TreeItem {
|
|
76
|
-
return element;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async getChildren(element?: DatabaseItem): Promise<DatabaseItem[]> {
|
|
80
|
-
if (!element) {
|
|
81
|
-
// 根节点:显示所有连接
|
|
82
|
-
const connections = await this.dbBridge.connection.getAllConnections();
|
|
83
|
-
return connections.map((conn: any) => {
|
|
84
|
-
const item = new DatabaseItem(
|
|
85
|
-
conn.name,
|
|
86
|
-
vscode.TreeItemCollapsibleState.Collapsed,
|
|
87
|
-
'connection',
|
|
88
|
-
conn
|
|
89
|
-
);
|
|
90
|
-
item.command = {
|
|
91
|
-
command: 'fdb2.openDatabasePanel',
|
|
92
|
-
title: '打开数据库',
|
|
93
|
-
arguments: [conn]
|
|
94
|
-
};
|
|
95
|
-
return item;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (element.contextValue === 'connection') {
|
|
100
|
-
// 连接节点:显示数据库列表(SQLite 不显示)
|
|
101
|
-
if (element.connection?.type === 'sqlite') {
|
|
102
|
-
return await this.getTables(element.connection, '');
|
|
103
|
-
}
|
|
104
|
-
return await this.getDatabases(element.connection);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (element.contextValue === 'database') {
|
|
108
|
-
// 数据库节点:显示表列表
|
|
109
|
-
return await this.getTables(element.connection, element.database?.name || '');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (element.contextValue === 'table' || element.contextValue === 'view') {
|
|
113
|
-
// 表节点:显示操作按钮
|
|
114
|
-
return [
|
|
115
|
-
new DatabaseItem('查看数据', vscode.TreeItemCollapsibleState.None, 'table-actions'),
|
|
116
|
-
new DatabaseItem('查看结构', vscode.TreeItemCollapsibleState.None, 'table-actions'),
|
|
117
|
-
new DatabaseItem('导出数据', vscode.TreeItemCollapsibleState.None, 'table-actions')
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 获取数据库列表
|
|
126
|
-
*/
|
|
127
|
-
private async getDatabases(connection: DatabaseConnection): Promise<DatabaseItem[]> {
|
|
128
|
-
if (!connection) return [];
|
|
129
|
-
try {
|
|
130
|
-
const databases = await this.dbBridge.database.getDatabases(connection.id);
|
|
131
|
-
return databases.map(db =>
|
|
132
|
-
new DatabaseItem(
|
|
133
|
-
db,
|
|
134
|
-
vscode.TreeItemCollapsibleState.Collapsed,
|
|
135
|
-
'database',
|
|
136
|
-
connection,
|
|
137
|
-
db
|
|
138
|
-
)
|
|
139
|
-
);
|
|
140
|
-
} catch (error: any) {
|
|
141
|
-
vscode.window.showErrorMessage(`获取数据库列表失败: ${error.message}`);
|
|
142
|
-
return [];
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 获取表列表
|
|
148
|
-
*/
|
|
149
|
-
private async getTables(connection: DatabaseConnection, databaseName: string): Promise<DatabaseItem[]> {
|
|
150
|
-
try {
|
|
151
|
-
const tables = await this.dbBridge.database.getTables(connection.id, databaseName);
|
|
152
|
-
return tables.map(table =>
|
|
153
|
-
new DatabaseItem(
|
|
154
|
-
table.name,
|
|
155
|
-
vscode.TreeItemCollapsibleState.Collapsed,
|
|
156
|
-
table.type === 'view' ? 'view' : 'table',
|
|
157
|
-
connection,
|
|
158
|
-
undefined,
|
|
159
|
-
table
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
} catch (error: any) {
|
|
163
|
-
vscode.window.showErrorMessage(`获取表列表失败: ${error.message}`);
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
import { DatabaseServiceBridge } from '../service/DatabaseServiceBridge';
|
|
3
|
+
import { DatabaseConnection, DatabaseInfo, TableInfo } from '../typings/connection';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 树形视图项目类型
|
|
7
|
+
*/
|
|
8
|
+
type TreeItemContext =
|
|
9
|
+
| 'connection' // 数据库连接
|
|
10
|
+
| 'database' // 数据库
|
|
11
|
+
| 'table' // 表
|
|
12
|
+
| 'view' // 视图
|
|
13
|
+
| 'table-actions'; // 表操作
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 树形视图项目
|
|
17
|
+
*/
|
|
18
|
+
class DatabaseItem extends vscode.TreeItem {
|
|
19
|
+
constructor(
|
|
20
|
+
public readonly label: string,
|
|
21
|
+
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
|
|
22
|
+
public readonly contextValue: TreeItemContext,
|
|
23
|
+
public readonly connection?: DatabaseConnection,
|
|
24
|
+
public readonly database?: DatabaseInfo,
|
|
25
|
+
public readonly table?: TableInfo
|
|
26
|
+
) {
|
|
27
|
+
super(label, collapsibleState);
|
|
28
|
+
|
|
29
|
+
// 设置图标
|
|
30
|
+
this.iconPath = this.getIconPath(contextValue);
|
|
31
|
+
|
|
32
|
+
// 设置描述
|
|
33
|
+
if (contextValue === 'connection' && connection) {
|
|
34
|
+
this.description = `${connection.host}:${connection.port}`;
|
|
35
|
+
} else if (contextValue === 'table' && table) {
|
|
36
|
+
this.description = table.type;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private getIconPath(contextValue: TreeItemContext): vscode.ThemeIcon {
|
|
41
|
+
switch (contextValue) {
|
|
42
|
+
case 'connection':
|
|
43
|
+
return new vscode.ThemeIcon('database');
|
|
44
|
+
case 'database':
|
|
45
|
+
return new vscode.ThemeIcon('server');
|
|
46
|
+
case 'table':
|
|
47
|
+
return new vscode.ThemeIcon('table');
|
|
48
|
+
case 'view':
|
|
49
|
+
return new vscode.ThemeIcon('preview');
|
|
50
|
+
case 'table-actions':
|
|
51
|
+
return new vscode.ThemeIcon('ellipsis');
|
|
52
|
+
default:
|
|
53
|
+
return new vscode.ThemeIcon('circle-outline');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 数据库树形视图提供者
|
|
60
|
+
* 提供侧边栏的数据库连接和结构树
|
|
61
|
+
*/
|
|
62
|
+
export class DatabaseTreeProvider implements vscode.TreeDataProvider<DatabaseItem> {
|
|
63
|
+
private _onDidChangeTreeData = new vscode.EventEmitter<DatabaseItem | undefined>();
|
|
64
|
+
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
|
|
65
|
+
|
|
66
|
+
constructor(
|
|
67
|
+
private context: vscode.ExtensionContext,
|
|
68
|
+
private dbBridge: DatabaseServiceBridge
|
|
69
|
+
) {}
|
|
70
|
+
|
|
71
|
+
refresh(): void {
|
|
72
|
+
this._onDidChangeTreeData.fire(undefined);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getTreeItem(element: DatabaseItem): vscode.TreeItem {
|
|
76
|
+
return element;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async getChildren(element?: DatabaseItem): Promise<DatabaseItem[]> {
|
|
80
|
+
if (!element) {
|
|
81
|
+
// 根节点:显示所有连接
|
|
82
|
+
const connections = await this.dbBridge.connection.getAllConnections();
|
|
83
|
+
return connections.map((conn: any) => {
|
|
84
|
+
const item = new DatabaseItem(
|
|
85
|
+
conn.name,
|
|
86
|
+
vscode.TreeItemCollapsibleState.Collapsed,
|
|
87
|
+
'connection',
|
|
88
|
+
conn
|
|
89
|
+
);
|
|
90
|
+
item.command = {
|
|
91
|
+
command: 'fdb2.openDatabasePanel',
|
|
92
|
+
title: '打开数据库',
|
|
93
|
+
arguments: [conn]
|
|
94
|
+
};
|
|
95
|
+
return item;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (element.contextValue === 'connection') {
|
|
100
|
+
// 连接节点:显示数据库列表(SQLite 不显示)
|
|
101
|
+
if (element.connection?.type === 'sqlite') {
|
|
102
|
+
return await this.getTables(element.connection, '');
|
|
103
|
+
}
|
|
104
|
+
return await this.getDatabases(element.connection);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (element.contextValue === 'database') {
|
|
108
|
+
// 数据库节点:显示表列表
|
|
109
|
+
return await this.getTables(element.connection, element.database?.name || '');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (element.contextValue === 'table' || element.contextValue === 'view') {
|
|
113
|
+
// 表节点:显示操作按钮
|
|
114
|
+
return [
|
|
115
|
+
new DatabaseItem('查看数据', vscode.TreeItemCollapsibleState.None, 'table-actions'),
|
|
116
|
+
new DatabaseItem('查看结构', vscode.TreeItemCollapsibleState.None, 'table-actions'),
|
|
117
|
+
new DatabaseItem('导出数据', vscode.TreeItemCollapsibleState.None, 'table-actions')
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 获取数据库列表
|
|
126
|
+
*/
|
|
127
|
+
private async getDatabases(connection: DatabaseConnection): Promise<DatabaseItem[]> {
|
|
128
|
+
if (!connection) return [];
|
|
129
|
+
try {
|
|
130
|
+
const databases = await this.dbBridge.database.getDatabases(connection.id);
|
|
131
|
+
return databases.map(db =>
|
|
132
|
+
new DatabaseItem(
|
|
133
|
+
db,
|
|
134
|
+
vscode.TreeItemCollapsibleState.Collapsed,
|
|
135
|
+
'database',
|
|
136
|
+
connection,
|
|
137
|
+
db
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
} catch (error: any) {
|
|
141
|
+
vscode.window.showErrorMessage(`获取数据库列表失败: ${error.message}`);
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 获取表列表
|
|
148
|
+
*/
|
|
149
|
+
private async getTables(connection: DatabaseConnection, databaseName: string): Promise<DatabaseItem[]> {
|
|
150
|
+
try {
|
|
151
|
+
const tables = await this.dbBridge.database.getTables(connection.id, databaseName);
|
|
152
|
+
return tables.map(table =>
|
|
153
|
+
new DatabaseItem(
|
|
154
|
+
table.name,
|
|
155
|
+
vscode.TreeItemCollapsibleState.Collapsed,
|
|
156
|
+
table.type === 'view' ? 'view' : 'table',
|
|
157
|
+
connection,
|
|
158
|
+
undefined,
|
|
159
|
+
table
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
} catch (error: any) {
|
|
163
|
+
vscode.window.showErrorMessage(`获取表列表失败: ${error.message}`);
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|