fdb2 1.0.13 → 1.0.14
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/README.md +9 -2
- package/bin/docker/.env +4 -0
- package/package.json +16 -8
- package/public/favicon.ico +0 -0
- package/public/favicon.png +0 -0
- package/view/modules/header.tpl +1 -1
- package/.dockerignore +0 -21
- package/.editorconfig +0 -11
- package/.eslintrc.cjs +0 -14
- package/.eslintrc.json +0 -7
- package/.prettierrc.js +0 -3
- package/.tpl.env +0 -22
- package/.vscodeignore +0 -45
- package/dist/package.json +0 -115
- package/dist/pnpm-lock.yaml +0 -8135
- package/dist/public/.vite/manifest.json +0 -82
- package/dist/public/bootstrap-icons.woff +0 -0
- package/dist/public/bootstrap-icons.woff2 +0 -0
- package/dist/public/bootstrap.css +0 -14152
- package/dist/public/bootstrap.js +0 -5038
- package/dist/public/explorer.css +0 -2379
- package/dist/public/explorer.js +0 -50586
- package/dist/public/index.css +0 -1099
- package/dist/public/index.js +0 -12862
- package/dist/public/layout.css +0 -318
- package/dist/public/layout.js +0 -25
- package/dist/public/vue.css +0 -1
- package/dist/public/vue.js +0 -9110
- package/dist/scripts/preinstall.js +0 -112
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -601
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.ts +0 -681
- package/dist/server/model/connection.entity.d.ts +0 -55
- package/dist/server/model/connection.entity.d.ts.map +0 -1
- package/dist/server/model/connection.entity.js +0 -59
- package/dist/server/model/connection.entity.js.map +0 -1
- package/dist/server/model/connection.entity.ts +0 -66
- package/dist/server/model/database.entity.d.ts +0 -203
- package/dist/server/model/database.entity.d.ts.map +0 -1
- package/dist/server/model/database.entity.js +0 -211
- package/dist/server/model/database.entity.js.map +0 -1
- package/dist/server/model/database.entity.ts +0 -246
- package/dist/server/service/connection.service.d.ts +0 -84
- package/dist/server/service/connection.service.d.ts.map +0 -1
- package/dist/server/service/connection.service.js +0 -369
- package/dist/server/service/connection.service.js.map +0 -1
- package/dist/server/service/connection.service.ts +0 -359
- package/dist/server/service/database/base.service.d.ts +0 -183
- package/dist/server/service/database/base.service.d.ts.map +0 -1
- package/dist/server/service/database/base.service.js +0 -253
- package/dist/server/service/database/base.service.js.map +0 -1
- package/dist/server/service/database/base.service.ts +0 -407
- package/dist/server/service/database/cockroachdb.service.d.ts +0 -116
- package/dist/server/service/database/cockroachdb.service.d.ts.map +0 -1
- package/dist/server/service/database/cockroachdb.service.js +0 -812
- package/dist/server/service/database/cockroachdb.service.js.map +0 -1
- package/dist/server/service/database/cockroachdb.service.ts +0 -871
- package/dist/server/service/database/database.service.d.ts +0 -495
- package/dist/server/service/database/database.service.d.ts.map +0 -1
- package/dist/server/service/database/database.service.js +0 -711
- package/dist/server/service/database/database.service.js.map +0 -1
- package/dist/server/service/database/database.service.ts +0 -776
- package/dist/server/service/database/index.d.ts +0 -8
- package/dist/server/service/database/index.d.ts.map +0 -1
- package/dist/server/service/database/index.js +0 -18
- package/dist/server/service/database/index.js.map +0 -1
- package/dist/server/service/database/index.ts +0 -7
- package/dist/server/service/database/mongodb.service.d.ts +0 -121
- package/dist/server/service/database/mongodb.service.d.ts.map +0 -1
- package/dist/server/service/database/mongodb.service.js +0 -502
- package/dist/server/service/database/mongodb.service.js.map +0 -1
- package/dist/server/service/database/mongodb.service.ts +0 -501
- package/dist/server/service/database/mssql.service.d.ts +0 -118
- package/dist/server/service/database/mssql.service.d.ts.map +0 -1
- package/dist/server/service/database/mssql.service.js +0 -871
- package/dist/server/service/database/mssql.service.js.map +0 -1
- package/dist/server/service/database/mssql.service.ts +0 -932
- package/dist/server/service/database/mysql.service.d.ts +0 -114
- package/dist/server/service/database/mysql.service.d.ts.map +0 -1
- package/dist/server/service/database/mysql.service.js +0 -960
- package/dist/server/service/database/mysql.service.js.map +0 -1
- package/dist/server/service/database/mysql.service.ts +0 -1026
- package/dist/server/service/database/oracle.service.d.ts +0 -126
- package/dist/server/service/database/oracle.service.d.ts.map +0 -1
- package/dist/server/service/database/oracle.service.js +0 -963
- package/dist/server/service/database/oracle.service.js.map +0 -1
- package/dist/server/service/database/oracle.service.ts +0 -1036
- package/dist/server/service/database/postgres.service.d.ts +0 -122
- package/dist/server/service/database/postgres.service.d.ts.map +0 -1
- package/dist/server/service/database/postgres.service.js +0 -882
- package/dist/server/service/database/postgres.service.js.map +0 -1
- package/dist/server/service/database/postgres.service.ts +0 -961
- package/dist/server/service/database/sap.service.d.ts +0 -115
- package/dist/server/service/database/sap.service.d.ts.map +0 -1
- package/dist/server/service/database/sap.service.js +0 -868
- package/dist/server/service/database/sap.service.js.map +0 -1
- package/dist/server/service/database/sap.service.ts +0 -922
- package/dist/server/service/database/sqlite.service.d.ts +0 -112
- package/dist/server/service/database/sqlite.service.d.ts.map +0 -1
- package/dist/server/service/database/sqlite.service.js +0 -723
- package/dist/server/service/database/sqlite.service.js.map +0 -1
- package/dist/server/service/database/sqlite.service.ts +0 -787
- package/dist/server/service/session.service.ts +0 -158
- package/dist/view/index.html +0 -45
- package/env.d.ts +0 -1
- package/packages/vscode/.vscodeignore +0 -44
- package/packages/vscode/README.md +0 -62
- package/packages/vscode/out/database-services/base.service.js +0 -236
- package/packages/vscode/out/database-services/base.service.js.map +0 -1
- package/packages/vscode/out/database-services/cockroachdb.service.js +0 -634
- package/packages/vscode/out/database-services/cockroachdb.service.js.map +0 -1
- package/packages/vscode/out/database-services/connection.service.js +0 -346
- package/packages/vscode/out/database-services/connection.service.js.map +0 -1
- package/packages/vscode/out/database-services/database.service.js +0 -571
- package/packages/vscode/out/database-services/database.service.js.map +0 -1
- package/packages/vscode/out/database-services/index.js +0 -18
- package/packages/vscode/out/database-services/index.js.map +0 -1
- package/packages/vscode/out/database-services/model/connection.entity.js +0 -11
- package/packages/vscode/out/database-services/model/connection.entity.js.map +0 -1
- package/packages/vscode/out/database-services/model/database.entity.js +0 -35
- package/packages/vscode/out/database-services/model/database.entity.js.map +0 -1
- package/packages/vscode/out/database-services/mongodb.service.js +0 -458
- package/packages/vscode/out/database-services/mongodb.service.js.map +0 -1
- package/packages/vscode/out/database-services/mssql.service.js +0 -694
- package/packages/vscode/out/database-services/mssql.service.js.map +0 -1
- package/packages/vscode/out/database-services/mysql.service.js +0 -735
- package/packages/vscode/out/database-services/mysql.service.js.map +0 -1
- package/packages/vscode/out/database-services/oracle.service.js +0 -787
- package/packages/vscode/out/database-services/oracle.service.js.map +0 -1
- package/packages/vscode/out/database-services/postgres.service.js +0 -696
- package/packages/vscode/out/database-services/postgres.service.js.map +0 -1
- package/packages/vscode/out/database-services/sap.service.js +0 -695
- package/packages/vscode/out/database-services/sap.service.js.map +0 -1
- package/packages/vscode/out/database-services/sqlite.service.js +0 -532
- package/packages/vscode/out/database-services/sqlite.service.js.map +0 -1
- package/packages/vscode/out/extension.js +0 -93
- package/packages/vscode/out/extension.js.map +0 -1
- package/packages/vscode/out/provider/DatabaseTreeProvider.js +0 -159
- package/packages/vscode/out/provider/DatabaseTreeProvider.js.map +0 -1
- package/packages/vscode/out/provider/WebViewProvider.js +0 -259
- package/packages/vscode/out/provider/WebViewProvider.js.map +0 -1
- package/packages/vscode/out/service/ConnectionManager.js +0 -105
- package/packages/vscode/out/service/ConnectionManager.js.map +0 -1
- package/packages/vscode/out/service/DatabaseServiceBridge.js +0 -395
- package/packages/vscode/out/service/DatabaseServiceBridge.js.map +0 -1
- package/packages/vscode/out/typings/connection.js +0 -3
- package/packages/vscode/out/typings/connection.js.map +0 -1
- package/packages/vscode/package.json +0 -144
- package/packages/vscode/resources/icon.svg +0 -5
- package/packages/vscode/resources/webview/_plugin-vue_export-helper.js +0 -6529
- package/packages/vscode/resources/webview/_plugin-vue_export-helper.js.map +0 -1
- package/packages/vscode/resources/webview/connection.css +0 -69
- package/packages/vscode/resources/webview/connection.js +0 -228
- package/packages/vscode/resources/webview/connection.js.map +0 -1
- package/packages/vscode/resources/webview/database.css +0 -259
- package/packages/vscode/resources/webview/database.js +0 -275
- package/packages/vscode/resources/webview/database.js.map +0 -1
- package/packages/vscode/resources/webview/favicon.ico +0 -0
- package/packages/vscode/resources/webview/index.html +0 -9
- package/packages/vscode/resources/webview/modules/header.tpl +0 -14
- package/packages/vscode/resources/webview/modules/initial_state.tpl +0 -55
- package/packages/vscode/resources/webview/query.css +0 -162
- package/packages/vscode/resources/webview/query.js +0 -198
- package/packages/vscode/resources/webview/query.js.map +0 -1
- package/packages/vscode/src/database-services/base.service.js.map +0 -1
- package/packages/vscode/src/database-services/base.service.ts +0 -363
- package/packages/vscode/src/database-services/cockroachdb.service.js.map +0 -1
- package/packages/vscode/src/database-services/cockroachdb.service.ts +0 -659
- package/packages/vscode/src/database-services/connection.service.ts +0 -341
- package/packages/vscode/src/database-services/database.service.ts +0 -630
- package/packages/vscode/src/database-services/index.ts +0 -7
- package/packages/vscode/src/database-services/model/connection.entity.js +0 -11
- package/packages/vscode/src/database-services/model/connection.entity.js.map +0 -1
- package/packages/vscode/src/database-services/model/connection.entity.ts +0 -66
- package/packages/vscode/src/database-services/model/database.entity.js +0 -35
- package/packages/vscode/src/database-services/model/database.entity.js.map +0 -1
- package/packages/vscode/src/database-services/model/database.entity.ts +0 -246
- package/packages/vscode/src/database-services/mongodb.service.js.map +0 -1
- package/packages/vscode/src/database-services/mongodb.service.ts +0 -454
- package/packages/vscode/src/database-services/mssql.service.js.map +0 -1
- package/packages/vscode/src/database-services/mssql.service.ts +0 -723
- package/packages/vscode/src/database-services/mysql.service.js.map +0 -1
- package/packages/vscode/src/database-services/mysql.service.ts +0 -761
- package/packages/vscode/src/database-services/oracle.service.js.map +0 -1
- package/packages/vscode/src/database-services/oracle.service.ts +0 -832
- package/packages/vscode/src/database-services/postgres.service.js.map +0 -1
- package/packages/vscode/src/database-services/postgres.service.ts +0 -741
- package/packages/vscode/src/database-services/sap.service.js.map +0 -1
- package/packages/vscode/src/database-services/sap.service.ts +0 -713
- package/packages/vscode/src/database-services/sqlite.service.js.map +0 -1
- package/packages/vscode/src/database-services/sqlite.service.ts +0 -558
- package/packages/vscode/src/extension.ts +0 -76
- package/packages/vscode/src/provider/DatabaseTreeProvider.ts +0 -167
- package/packages/vscode/src/provider/WebViewProvider.ts +0 -277
- package/packages/vscode/src/service/DatabaseServiceBridge.ts +0 -414
- package/packages/vscode/src/typings/connection.ts +0 -90
- package/packages/vscode/tsconfig.json +0 -21
- package/scripts/preinstall.js +0 -112
- package/server/index.ts +0 -681
- package/server/model/connection.entity.js +0 -11
- package/server/model/connection.entity.js.map +0 -1
- package/server/model/connection.entity.ts +0 -66
- package/server/model/database.entity.js +0 -35
- package/server/model/database.entity.js.map +0 -1
- package/server/model/database.entity.ts +0 -246
- package/server/service/connection.service.ts +0 -359
- package/server/service/database/base.service.ts +0 -407
- package/server/service/database/cockroachdb.service.ts +0 -871
- package/server/service/database/database.service.ts +0 -776
- package/server/service/database/index.ts +0 -7
- package/server/service/database/mongodb.service.ts +0 -501
- package/server/service/database/mssql.service.ts +0 -932
- package/server/service/database/mysql.service.ts +0 -1026
- package/server/service/database/oracle.service.ts +0 -1036
- package/server/service/database/postgres.service.ts +0 -961
- package/server/service/database/sap.service.ts +0 -922
- package/server/service/database/sqlite.service.ts +0 -787
- package/server/service/session.service.ts +0 -158
- package/server/tsconfig.json +0 -20
- package/src/adapter/ajax.ts +0 -135
- package/src/assets/base.css +0 -1
- package/src/assets/database.css +0 -950
- 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 +0 -1
- package/src/assets/images/svg/illustrations/illustration-2.svg +0 -2
- package/src/assets/images/svg/illustrations/illustration-3.svg +0 -50
- package/src/assets/images/svg/illustrations/illustration-4.svg +0 -1
- package/src/assets/images/svg/illustrations/illustration-5.svg +0 -73
- package/src/assets/images/svg/illustrations/illustration-6.svg +0 -89
- package/src/assets/images/svg/illustrations/illustration-7.svg +0 -39
- package/src/assets/images/svg/illustrations/illustration-8.svg +0 -1
- package/src/assets/images/svg/separators/curve-2.svg +0 -3
- package/src/assets/images/svg/separators/curve.svg +0 -3
- package/src/assets/images/svg/separators/line.svg +0 -3
- 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 +0 -73
- package/src/assets/logo.webp +0 -0
- package/src/assets/main.css +0 -1
- package/src/base/config.ts +0 -20
- package/src/base/detect.ts +0 -134
- package/src/base/entity.ts +0 -92
- package/src/base/eventBus.ts +0 -37
- package/src/components/connection-editor/index.vue +0 -589
- package/src/components/dataGrid/index.vue +0 -163
- package/src/components/dataGrid/pagination.vue +0 -106
- package/src/components/loading/index.vue +0 -43
- package/src/components/modal/index.ts +0 -181
- package/src/components/modal/index.vue +0 -560
- package/src/components/toast/index.ts +0 -44
- package/src/components/toast/toast.vue +0 -58
- package/src/components/user/name.vue +0 -104
- package/src/components/user/selector.vue +0 -416
- package/src/domain/SysConfig.ts +0 -74
- package/src/platform/App.vue +0 -8
- package/src/platform/database/components/connection-detail.vue +0 -1153
- package/src/platform/database/components/data-editor.vue +0 -478
- package/src/platform/database/components/data-import-export.vue +0 -1602
- package/src/platform/database/components/database-detail.vue +0 -1199
- package/src/platform/database/components/database-monitor.vue +0 -1086
- package/src/platform/database/components/db-tools.vue +0 -1265
- package/src/platform/database/components/query-history.vue +0 -1349
- package/src/platform/database/components/sql-executor.vue +0 -738
- package/src/platform/database/components/sql-query-editor.vue +0 -1046
- package/src/platform/database/components/table-data-grid.vue +0 -273
- package/src/platform/database/components/table-detail.vue +0 -1173
- package/src/platform/database/components/table-editor.vue +0 -917
- package/src/platform/database/explorer.vue +0 -1840
- package/src/platform/database/index.vue +0 -1193
- package/src/platform/database/layout.vue +0 -367
- package/src/platform/database/router.ts +0 -37
- package/src/platform/database/styles/common.scss +0 -602
- package/src/platform/database/types/common.ts +0 -445
- package/src/platform/database/utils/export.ts +0 -232
- package/src/platform/database/utils/helpers.ts +0 -437
- package/src/platform/index.ts +0 -33
- package/src/platform/router.ts +0 -41
- package/src/platform/vscode/bridge.ts +0 -121
- package/src/platform/vscode/components/ConnectionPanel.vue +0 -272
- package/src/platform/vscode/components/DatabasePanel.vue +0 -532
- package/src/platform/vscode/components/QueryPanel.vue +0 -371
- package/src/platform/vscode/entry/connection.ts +0 -13
- package/src/platform/vscode/entry/database.ts +0 -13
- package/src/platform/vscode/entry/query.ts +0 -13
- package/src/platform/vscode/index.ts +0 -5
- package/src/service/base.ts +0 -134
- package/src/service/database.ts +0 -506
- package/src/service/login.ts +0 -121
- package/src/shims-vue.d.ts +0 -7
- package/src/stores/connection.ts +0 -266
- package/src/stores/session.ts +0 -87
- package/src/typings/database-types.ts +0 -413
- package/src/typings/database.ts +0 -364
- package/src/typings/global.d.ts +0 -58
- package/src/typings/pinia.d.ts +0 -8
- package/src/utils/clipboard.ts +0 -30
- package/src/utils/database-types.ts +0 -243
- package/src/utils/modal.ts +0 -124
- package/src/utils/request.ts +0 -55
- package/src/utils/sleep.ts +0 -4
- package/src/utils/toast.ts +0 -73
- package/src/utils/util.ts +0 -171
- package/src/utils/xlsx.ts +0 -228
- package/tsconfig.json +0 -33
- package/tsconfig.server.json +0 -19
- package/vite.config.ts +0 -424
- package/vite.config.vscode.ts +0 -47
|
@@ -1,8 +0,0 @@
|
|
|
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';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/service/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatabaseService = exports.SQLServerService = exports.OracleService = exports.SQLiteService = exports.PostgreSQLService = exports.MySQLService = exports.BaseDatabaseService = void 0;
|
|
4
|
-
var base_service_1 = require("./base.service");
|
|
5
|
-
Object.defineProperty(exports, "BaseDatabaseService", { enumerable: true, get: function () { return base_service_1.BaseDatabaseService; } });
|
|
6
|
-
var mysql_service_1 = require("./mysql.service");
|
|
7
|
-
Object.defineProperty(exports, "MySQLService", { enumerable: true, get: function () { return mysql_service_1.MySQLService; } });
|
|
8
|
-
var postgres_service_1 = require("./postgres.service");
|
|
9
|
-
Object.defineProperty(exports, "PostgreSQLService", { enumerable: true, get: function () { return postgres_service_1.PostgreSQLService; } });
|
|
10
|
-
var sqlite_service_1 = require("./sqlite.service");
|
|
11
|
-
Object.defineProperty(exports, "SQLiteService", { enumerable: true, get: function () { return sqlite_service_1.SQLiteService; } });
|
|
12
|
-
var oracle_service_1 = require("./oracle.service");
|
|
13
|
-
Object.defineProperty(exports, "OracleService", { enumerable: true, get: function () { return oracle_service_1.OracleService; } });
|
|
14
|
-
var mssql_service_1 = require("./mssql.service");
|
|
15
|
-
Object.defineProperty(exports, "SQLServerService", { enumerable: true, get: function () { return mssql_service_1.SQLServerService; } });
|
|
16
|
-
var database_service_1 = require("./database.service");
|
|
17
|
-
Object.defineProperty(exports, "DatabaseService", { enumerable: true, get: function () { return database_service_1.DatabaseService; } });
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/service/database/index.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AAA5C,mHAAA,mBAAmB,OAAA;AAC5B,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,uDAAuD;AAA9C,qHAAA,iBAAiB,OAAA;AAC1B,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,iDAAmD;AAA1C,iHAAA,gBAAgB,OAAA;AACzB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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';
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { DataSource } from 'typeorm';
|
|
2
|
-
import { BaseDatabaseService } from './base.service';
|
|
3
|
-
import { TableEntity, ColumnEntity, IndexEntity, ForeignKeyEntity } from '../../model/database.entity';
|
|
4
|
-
/**
|
|
5
|
-
* MongoDB数据库服务实现
|
|
6
|
-
* MongoDB 是一个 NoSQL 文档数据库,与关系型数据库有很大不同
|
|
7
|
-
*/
|
|
8
|
-
export declare class MongoDBService extends BaseDatabaseService {
|
|
9
|
-
getDatabaseType(): string;
|
|
10
|
-
/**
|
|
11
|
-
* 获取MongoDB数据库列表
|
|
12
|
-
*/
|
|
13
|
-
getDatabases(dataSource: DataSource): Promise<string[]>;
|
|
14
|
-
/**
|
|
15
|
-
* 获取MongoDB集合列表(相当于关系型数据库的表)
|
|
16
|
-
*/
|
|
17
|
-
getTables(dataSource: DataSource, database: string): Promise<TableEntity[]>;
|
|
18
|
-
/**
|
|
19
|
-
* 获取MongoDB集合的字段信息(文档结构)
|
|
20
|
-
*/
|
|
21
|
-
getColumns(dataSource: DataSource, database: string, table: string): Promise<ColumnEntity[]>;
|
|
22
|
-
/**
|
|
23
|
-
* 推断字段类型
|
|
24
|
-
*/
|
|
25
|
-
private inferType;
|
|
26
|
-
/**
|
|
27
|
-
* 获取MongoDB索引信息
|
|
28
|
-
*/
|
|
29
|
-
getIndexes(dataSource: DataSource, database: string, table: string): Promise<IndexEntity[]>;
|
|
30
|
-
/**
|
|
31
|
-
* MongoDB不支持外键
|
|
32
|
-
*/
|
|
33
|
-
getForeignKeys(dataSource: DataSource, database: string, table: string): Promise<ForeignKeyEntity[]>;
|
|
34
|
-
/**
|
|
35
|
-
* 获取MongoDB数据库大小
|
|
36
|
-
*/
|
|
37
|
-
getDatabaseSize(dataSource: DataSource, database: string): Promise<number>;
|
|
38
|
-
/**
|
|
39
|
-
* MongoDB不支持视图
|
|
40
|
-
*/
|
|
41
|
-
getViews(dataSource: DataSource, database: string): Promise<any[]>;
|
|
42
|
-
/**
|
|
43
|
-
* MongoDB不支持视图
|
|
44
|
-
*/
|
|
45
|
-
getViewDefinition(dataSource: DataSource, database: string, viewName: string): Promise<string>;
|
|
46
|
-
/**
|
|
47
|
-
* MongoDB不支持存储过程
|
|
48
|
-
*/
|
|
49
|
-
getProcedures(dataSource: DataSource, database: string): Promise<any[]>;
|
|
50
|
-
/**
|
|
51
|
-
* MongoDB不支持存储过程
|
|
52
|
-
*/
|
|
53
|
-
getProcedureDefinition(dataSource: DataSource, database: string, procedureName: string): Promise<string>;
|
|
54
|
-
/**
|
|
55
|
-
* 创建MongoDB数据库
|
|
56
|
-
*/
|
|
57
|
-
createDatabase(dataSource: DataSource, databaseName: string, options?: any): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* 删除MongoDB数据库
|
|
60
|
-
*/
|
|
61
|
-
dropDatabase(dataSource: DataSource, databaseName: string): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* 导出数据库架构
|
|
64
|
-
*/
|
|
65
|
-
exportSchema(dataSource: DataSource, databaseName: string): Promise<string>;
|
|
66
|
-
/**
|
|
67
|
-
* 查看MongoDB日志
|
|
68
|
-
*/
|
|
69
|
-
viewLogs(dataSource: DataSource, database?: string, limit?: number): Promise<any[]>;
|
|
70
|
-
/**
|
|
71
|
-
* 备份MongoDB数据库
|
|
72
|
-
*/
|
|
73
|
-
backupDatabase(dataSource: DataSource, databaseName: string, options?: any): Promise<string>;
|
|
74
|
-
/**
|
|
75
|
-
* 恢复MongoDB数据库
|
|
76
|
-
*/
|
|
77
|
-
restoreDatabase(dataSource: DataSource, databaseName: string, filePath: string, options?: any): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* 导出表数据到 SQL 文件(MongoDB不支持SQL)
|
|
80
|
-
*/
|
|
81
|
-
exportTableDataToSQL(dataSource: DataSource, databaseName: string, tableName: string, options?: any): Promise<string>;
|
|
82
|
-
/**
|
|
83
|
-
* 导出表数据到 CSV 文件
|
|
84
|
-
*/
|
|
85
|
-
exportTableDataToCSV(dataSource: DataSource, databaseName: string, tableName: string, options?: any): Promise<string>;
|
|
86
|
-
/**
|
|
87
|
-
* 导出表数据到 JSON 文件
|
|
88
|
-
*/
|
|
89
|
-
exportTableDataToJSON(dataSource: DataSource, databaseName: string, tableName: string, options?: any): Promise<string>;
|
|
90
|
-
/**
|
|
91
|
-
* 导出表数据到 Excel 文件
|
|
92
|
-
*/
|
|
93
|
-
exportTableDataToExcel(dataSource: DataSource, databaseName: string, tableName: string, options?: any): Promise<string>;
|
|
94
|
-
/**
|
|
95
|
-
* MongoDB使用反引号作为标识符
|
|
96
|
-
*/
|
|
97
|
-
quoteIdentifier(identifier: string): string;
|
|
98
|
-
/**
|
|
99
|
-
* 修改表结构
|
|
100
|
-
* MongoDB是文档数据库,没有传统的表结构概念
|
|
101
|
-
* 集合中的文档可以有不同的结构,因此不需要ALTER TABLE
|
|
102
|
-
*/
|
|
103
|
-
alterTable(dataSource: DataSource, databaseName: string, tableDiff: any): Promise<any>;
|
|
104
|
-
/**
|
|
105
|
-
* 批量插入数据
|
|
106
|
-
*/
|
|
107
|
-
bulkInsert(dataSource: DataSource, databaseName: string, tableName: string, data: any[]): Promise<void>;
|
|
108
|
-
/**
|
|
109
|
-
* 插入单条数据
|
|
110
|
-
*/
|
|
111
|
-
insertData(dataSource: DataSource, databaseName: string, tableName: string, data: any): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
* 删除表(集合)
|
|
114
|
-
*/
|
|
115
|
-
dropTable(dataSource: DataSource, databaseName: string, tableName: string): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* 创建表(集合)
|
|
118
|
-
*/
|
|
119
|
-
createTable(dataSource: DataSource, databaseName: string, table: any): Promise<void>;
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=mongodb.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb.service.d.ts","sourceRoot":"","sources":["../../../../server/service/database/mongodb.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.MongoDBService = void 0;
|
|
37
|
-
const base_service_1 = require("./base.service");
|
|
38
|
-
const fs = __importStar(require("fs"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
/**
|
|
41
|
-
* MongoDB数据库服务实现
|
|
42
|
-
* MongoDB 是一个 NoSQL 文档数据库,与关系型数据库有很大不同
|
|
43
|
-
*/
|
|
44
|
-
class MongoDBService extends base_service_1.BaseDatabaseService {
|
|
45
|
-
getDatabaseType() {
|
|
46
|
-
return 'mongodb';
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 获取MongoDB数据库列表
|
|
50
|
-
*/
|
|
51
|
-
async getDatabases(dataSource) {
|
|
52
|
-
try {
|
|
53
|
-
const result = await dataSource.query(`db.adminCommand({ listDatabases: 1 })`);
|
|
54
|
-
return result.databases.map((db) => db.name).filter((name) => name !== 'admin' && name !== 'local' && name !== 'config');
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
console.error('获取MongoDB数据库列表失败:', error);
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 获取MongoDB集合列表(相当于关系型数据库的表)
|
|
63
|
-
*/
|
|
64
|
-
async getTables(dataSource, database) {
|
|
65
|
-
try {
|
|
66
|
-
const result = await dataSource.query(`db.getCollectionNames()`);
|
|
67
|
-
return result.map((collectionName) => ({
|
|
68
|
-
name: collectionName,
|
|
69
|
-
type: 'collection',
|
|
70
|
-
rowCount: undefined,
|
|
71
|
-
dataSize: undefined,
|
|
72
|
-
indexSize: undefined
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.error('获取MongoDB集合列表失败:', error);
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 获取MongoDB集合的字段信息(文档结构)
|
|
82
|
-
*/
|
|
83
|
-
async getColumns(dataSource, database, table) {
|
|
84
|
-
try {
|
|
85
|
-
const result = await dataSource.query(`db.${table}.findOne()`);
|
|
86
|
-
if (!result) {
|
|
87
|
-
return [];
|
|
88
|
-
}
|
|
89
|
-
const fields = Object.keys(result);
|
|
90
|
-
return fields.map(field => ({
|
|
91
|
-
name: field,
|
|
92
|
-
type: this.inferType(result[field]),
|
|
93
|
-
nullable: true,
|
|
94
|
-
defaultValue: undefined,
|
|
95
|
-
isPrimary: field === '_id',
|
|
96
|
-
isAutoIncrement: field === '_id'
|
|
97
|
-
}));
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
console.error('获取MongoDB集合字段信息失败:', error);
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 推断字段类型
|
|
106
|
-
*/
|
|
107
|
-
inferType(value) {
|
|
108
|
-
if (value === null || value === undefined) {
|
|
109
|
-
return 'null';
|
|
110
|
-
}
|
|
111
|
-
const type = typeof value;
|
|
112
|
-
if (type === 'string') {
|
|
113
|
-
return 'string';
|
|
114
|
-
}
|
|
115
|
-
else if (type === 'number') {
|
|
116
|
-
return Number.isInteger(value) ? 'int' : 'double';
|
|
117
|
-
}
|
|
118
|
-
else if (type === 'boolean') {
|
|
119
|
-
return 'boolean';
|
|
120
|
-
}
|
|
121
|
-
else if (type === 'object') {
|
|
122
|
-
if (Array.isArray(value)) {
|
|
123
|
-
return 'array';
|
|
124
|
-
}
|
|
125
|
-
else if (value instanceof Date) {
|
|
126
|
-
return 'date';
|
|
127
|
-
}
|
|
128
|
-
else if (value instanceof Buffer) {
|
|
129
|
-
return 'binData';
|
|
130
|
-
}
|
|
131
|
-
else if (value instanceof ObjectId) {
|
|
132
|
-
return 'objectId';
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return 'object';
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return 'unknown';
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 获取MongoDB索引信息
|
|
142
|
-
*/
|
|
143
|
-
async getIndexes(dataSource, database, table) {
|
|
144
|
-
try {
|
|
145
|
-
const result = await dataSource.query(`db.${table}.getIndexes()`);
|
|
146
|
-
return result.map((index) => ({
|
|
147
|
-
name: index.name,
|
|
148
|
-
type: index.unique ? 'UNIQUE' : 'INDEX',
|
|
149
|
-
columns: Object.keys(index.key),
|
|
150
|
-
unique: index.unique || false
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
console.error('获取MongoDB索引信息失败:', error);
|
|
155
|
-
return [];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* MongoDB不支持外键
|
|
160
|
-
*/
|
|
161
|
-
async getForeignKeys(dataSource, database, table) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* 获取MongoDB数据库大小
|
|
166
|
-
*/
|
|
167
|
-
async getDatabaseSize(dataSource, database) {
|
|
168
|
-
try {
|
|
169
|
-
const result = await dataSource.query(`db.stats({ scale: 1 })`);
|
|
170
|
-
return result.dataSize || 0;
|
|
171
|
-
}
|
|
172
|
-
catch (error) {
|
|
173
|
-
console.error('获取MongoDB数据库大小失败:', error);
|
|
174
|
-
return 0;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* MongoDB不支持视图
|
|
179
|
-
*/
|
|
180
|
-
async getViews(dataSource, database) {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* MongoDB不支持视图
|
|
185
|
-
*/
|
|
186
|
-
async getViewDefinition(dataSource, database, viewName) {
|
|
187
|
-
throw new Error('MongoDB不支持视图');
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* MongoDB不支持存储过程
|
|
191
|
-
*/
|
|
192
|
-
async getProcedures(dataSource, database) {
|
|
193
|
-
return [];
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* MongoDB不支持存储过程
|
|
197
|
-
*/
|
|
198
|
-
async getProcedureDefinition(dataSource, database, procedureName) {
|
|
199
|
-
throw new Error('MongoDB不支持存储过程');
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* 创建MongoDB数据库
|
|
203
|
-
*/
|
|
204
|
-
async createDatabase(dataSource, databaseName, options) {
|
|
205
|
-
try {
|
|
206
|
-
await dataSource.query(`db.getSiblingDB('${databaseName}').createCollection('temp')`);
|
|
207
|
-
await dataSource.query(`db.getSiblingDB('${databaseName}').temp.drop()`);
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
console.error('创建MongoDB数据库失败:', error);
|
|
211
|
-
throw new Error(`创建数据库失败: ${error.message}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 删除MongoDB数据库
|
|
216
|
-
*/
|
|
217
|
-
async dropDatabase(dataSource, databaseName) {
|
|
218
|
-
try {
|
|
219
|
-
await dataSource.query(`db.getSiblingDB('${databaseName}').dropDatabase()`);
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
console.error('删除MongoDB数据库失败:', error);
|
|
223
|
-
throw new Error(`删除数据库失败: ${error.message}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* 导出数据库架构
|
|
228
|
-
*/
|
|
229
|
-
async exportSchema(dataSource, databaseName) {
|
|
230
|
-
const collections = await this.getTables(dataSource, databaseName);
|
|
231
|
-
let schemaSql = `-- MongoDB数据库架构导出 - ${databaseName}\n`;
|
|
232
|
-
schemaSql += `-- 导出时间: ${new Date().toISOString()}\n\n`;
|
|
233
|
-
for (const collection of collections) {
|
|
234
|
-
const columns = await this.getColumns(dataSource, databaseName, collection.name);
|
|
235
|
-
const indexes = await this.getIndexes(dataSource, databaseName, collection.name);
|
|
236
|
-
schemaSql += `// 集合: ${collection.name}\n`;
|
|
237
|
-
schemaSql += `// 字段:\n`;
|
|
238
|
-
columns.forEach(column => {
|
|
239
|
-
schemaSql += `// ${column.name}: ${column.type}${column.isPrimary ? ' (主键)' : ''}\n`;
|
|
240
|
-
});
|
|
241
|
-
schemaSql += `\n`;
|
|
242
|
-
if (indexes.length > 0) {
|
|
243
|
-
schemaSql += `// 索引:\n`;
|
|
244
|
-
indexes.forEach(index => {
|
|
245
|
-
schemaSql += `// ${index.name}: ${index.type} (${index.columns.join(', ')})\n`;
|
|
246
|
-
});
|
|
247
|
-
schemaSql += `\n`;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return schemaSql;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* 查看MongoDB日志
|
|
254
|
-
*/
|
|
255
|
-
async viewLogs(dataSource, database, limit = 100) {
|
|
256
|
-
try {
|
|
257
|
-
const result = await dataSource.query(`db.getSiblingDB('admin').adminCommand({ getLog: 'global' })`);
|
|
258
|
-
return result.log || [];
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
console.error('获取MongoDB日志失败:', error);
|
|
262
|
-
return [{ message: 'MongoDB日志功能需要管理员权限,请检查数据库配置' }];
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* 备份MongoDB数据库
|
|
267
|
-
*/
|
|
268
|
-
async backupDatabase(dataSource, databaseName, options) {
|
|
269
|
-
try {
|
|
270
|
-
const backupPath = options?.path || path.join(__dirname, '..', '..', '..', 'data', 'backups');
|
|
271
|
-
if (!fs.existsSync(backupPath)) {
|
|
272
|
-
fs.mkdirSync(backupPath, { recursive: true });
|
|
273
|
-
}
|
|
274
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
275
|
-
const backupFile = path.join(backupPath, `${databaseName}_${timestamp}.json`);
|
|
276
|
-
const collections = await this.getTables(dataSource, databaseName);
|
|
277
|
-
const backupData = {
|
|
278
|
-
database: databaseName,
|
|
279
|
-
exportedAt: new Date().toISOString(),
|
|
280
|
-
collections: {}
|
|
281
|
-
};
|
|
282
|
-
for (const collection of collections) {
|
|
283
|
-
const result = await dataSource.query(`db.${collection.name}.find().toArray()`);
|
|
284
|
-
backupData.collections[collection.name] = result;
|
|
285
|
-
}
|
|
286
|
-
fs.writeFileSync(backupFile, JSON.stringify(backupData, null, 2), 'utf8');
|
|
287
|
-
return `备份成功:${backupFile}`;
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
console.error('MongoDB备份失败:', error);
|
|
291
|
-
throw new Error(`备份失败: ${error.message}`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* 恢复MongoDB数据库
|
|
296
|
-
*/
|
|
297
|
-
async restoreDatabase(dataSource, databaseName, filePath, options) {
|
|
298
|
-
try {
|
|
299
|
-
const backupData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
300
|
-
for (const collectionName in backupData.collections) {
|
|
301
|
-
const documents = backupData.collections[collectionName];
|
|
302
|
-
if (documents.length > 0) {
|
|
303
|
-
await dataSource.query(`db.${collectionName}.insertMany(${JSON.stringify(documents)})`);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
catch (error) {
|
|
308
|
-
console.error('MongoDB恢复失败:', error);
|
|
309
|
-
throw new Error(`恢复失败: ${error.message}`);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* 导出表数据到 SQL 文件(MongoDB不支持SQL)
|
|
314
|
-
*/
|
|
315
|
-
async exportTableDataToSQL(dataSource, databaseName, tableName, options) {
|
|
316
|
-
throw new Error('MongoDB不支持导出为SQL格式,请使用JSON格式');
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* 导出表数据到 CSV 文件
|
|
320
|
-
*/
|
|
321
|
-
async exportTableDataToCSV(dataSource, databaseName, tableName, options) {
|
|
322
|
-
try {
|
|
323
|
-
const exportPath = options?.path || path.join(__dirname, '..', '..', '..', 'data', 'exports');
|
|
324
|
-
if (!fs.existsSync(exportPath)) {
|
|
325
|
-
fs.mkdirSync(exportPath, { recursive: true });
|
|
326
|
-
}
|
|
327
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
328
|
-
const exportFile = path.join(exportPath, `${tableName}_data_${timestamp}.csv`);
|
|
329
|
-
const result = await dataSource.query(`db.${tableName}.find().toArray()`);
|
|
330
|
-
if (result.length === 0) {
|
|
331
|
-
fs.writeFileSync(exportFile, '', 'utf8');
|
|
332
|
-
return exportFile;
|
|
333
|
-
}
|
|
334
|
-
const columns = await this.getColumns(dataSource, databaseName, tableName);
|
|
335
|
-
const columnNames = columns.map(column => column.name);
|
|
336
|
-
const bom = Buffer.from([0xEF, 0xBB, 0xBF]);
|
|
337
|
-
fs.writeFileSync(exportFile, bom);
|
|
338
|
-
fs.appendFileSync(exportFile, columnNames.map(name => `"${name}"`).join(',') + '\n', 'utf8');
|
|
339
|
-
let csv = '';
|
|
340
|
-
result.forEach((doc) => {
|
|
341
|
-
const values = columnNames.map(column => {
|
|
342
|
-
const value = doc[column];
|
|
343
|
-
if (value === null || value === undefined) {
|
|
344
|
-
return '';
|
|
345
|
-
}
|
|
346
|
-
else if (typeof value === 'string') {
|
|
347
|
-
return `"${value.replace(/"/g, '""')}"`;
|
|
348
|
-
}
|
|
349
|
-
else if (value instanceof Date) {
|
|
350
|
-
return `"${value.toISOString()}"`;
|
|
351
|
-
}
|
|
352
|
-
else if (typeof value === 'object' && value !== null) {
|
|
353
|
-
try {
|
|
354
|
-
return `"${JSON.stringify(value).replace(/"/g, '""')}"`;
|
|
355
|
-
}
|
|
356
|
-
catch {
|
|
357
|
-
return `"${String(value).replace(/"/g, '""')}"`;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
return String(value);
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
csv += values.join(',') + '\n';
|
|
365
|
-
});
|
|
366
|
-
fs.appendFileSync(exportFile, csv, 'utf8');
|
|
367
|
-
return exportFile;
|
|
368
|
-
}
|
|
369
|
-
catch (error) {
|
|
370
|
-
console.error('MongoDB导出表数据到CSV失败:', error);
|
|
371
|
-
throw new Error(`导出表数据到CSV失败: ${error.message}`);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* 导出表数据到 JSON 文件
|
|
376
|
-
*/
|
|
377
|
-
async exportTableDataToJSON(dataSource, databaseName, tableName, options) {
|
|
378
|
-
try {
|
|
379
|
-
const exportPath = options?.path || path.join(__dirname, '..', '..', '..', 'data', 'exports');
|
|
380
|
-
if (!fs.existsSync(exportPath)) {
|
|
381
|
-
fs.mkdirSync(exportPath, { recursive: true });
|
|
382
|
-
}
|
|
383
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
384
|
-
const exportFile = path.join(exportPath, `${tableName}_data_${timestamp}.json`);
|
|
385
|
-
const result = await dataSource.query(`db.${tableName}.find().toArray()`);
|
|
386
|
-
fs.writeFileSync(exportFile, JSON.stringify(result, null, 2), 'utf8');
|
|
387
|
-
return exportFile;
|
|
388
|
-
}
|
|
389
|
-
catch (error) {
|
|
390
|
-
console.error('MongoDB导出表数据到JSON失败:', error);
|
|
391
|
-
throw new Error(`导出表数据到JSON失败: ${error.message}`);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* 导出表数据到 Excel 文件
|
|
396
|
-
*/
|
|
397
|
-
async exportTableDataToExcel(dataSource, databaseName, tableName, options) {
|
|
398
|
-
try {
|
|
399
|
-
const exportPath = options?.path || path.join(__dirname, '..', '..', '..', 'data', 'exports');
|
|
400
|
-
if (!fs.existsSync(exportPath)) {
|
|
401
|
-
fs.mkdirSync(exportPath, { recursive: true });
|
|
402
|
-
}
|
|
403
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
404
|
-
const exportFile = path.join(exportPath, `${tableName}_data_${timestamp}.xlsx`);
|
|
405
|
-
const result = await dataSource.query(`db.${tableName}.find().toArray()`);
|
|
406
|
-
const columns = await this.getColumns(dataSource, databaseName, tableName);
|
|
407
|
-
const columnNames = columns.map(column => column.name);
|
|
408
|
-
const ExcelJS = require('exceljs');
|
|
409
|
-
const workbook = new ExcelJS.Workbook();
|
|
410
|
-
const worksheet = workbook.addWorksheet(tableName);
|
|
411
|
-
worksheet.columns = columnNames.map(name => ({
|
|
412
|
-
header: name,
|
|
413
|
-
key: name
|
|
414
|
-
}));
|
|
415
|
-
const flatData = result.map(doc => {
|
|
416
|
-
const flatDoc = {};
|
|
417
|
-
columnNames.forEach(column => {
|
|
418
|
-
const value = doc[column];
|
|
419
|
-
if (value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
|
|
420
|
-
flatDoc[column] = JSON.stringify(value);
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
flatDoc[column] = value;
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
return flatDoc;
|
|
427
|
-
});
|
|
428
|
-
worksheet.addRows(flatData);
|
|
429
|
-
await workbook.xlsx.writeFile(exportFile);
|
|
430
|
-
return exportFile;
|
|
431
|
-
}
|
|
432
|
-
catch (error) {
|
|
433
|
-
console.error('MongoDB导出表数据到Excel失败:', error);
|
|
434
|
-
throw new Error(`导出表数据到Excel失败: ${error.message}`);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* MongoDB使用反引号作为标识符
|
|
439
|
-
*/
|
|
440
|
-
quoteIdentifier(identifier) {
|
|
441
|
-
return `\`${identifier}\``;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* 修改表结构
|
|
445
|
-
* MongoDB是文档数据库,没有传统的表结构概念
|
|
446
|
-
* 集合中的文档可以有不同的结构,因此不需要ALTER TABLE
|
|
447
|
-
*/
|
|
448
|
-
async alterTable(dataSource, databaseName, tableDiff) {
|
|
449
|
-
return { ret: 0, message: 'MongoDB是文档数据库,不需要修改表结构' };
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* 批量插入数据
|
|
453
|
-
*/
|
|
454
|
-
async bulkInsert(dataSource, databaseName, tableName, data) {
|
|
455
|
-
if (data.length === 0)
|
|
456
|
-
return;
|
|
457
|
-
// MongoDB使用Repository模式
|
|
458
|
-
const repository = dataSource.getMongoRepository(tableName);
|
|
459
|
-
await repository.insertMany(data);
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* 插入单条数据
|
|
463
|
-
*/
|
|
464
|
-
async insertData(dataSource, databaseName, tableName, data) {
|
|
465
|
-
// MongoDB使用Repository模式
|
|
466
|
-
const repository = dataSource.getMongoRepository(tableName);
|
|
467
|
-
await repository.insertOne(data);
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* 删除表(集合)
|
|
471
|
-
*/
|
|
472
|
-
async dropTable(dataSource, databaseName, tableName) {
|
|
473
|
-
// MongoDB使用Repository模式
|
|
474
|
-
const repository = dataSource.getMongoRepository(tableName);
|
|
475
|
-
await repository.deleteMany({});
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* 创建表(集合)
|
|
479
|
-
*/
|
|
480
|
-
async createTable(dataSource, databaseName, table) {
|
|
481
|
-
const { name } = table;
|
|
482
|
-
// MongoDB会自动创建集合,无需显式创建
|
|
483
|
-
await this.insertData(dataSource, databaseName, name, {});
|
|
484
|
-
await this.dropTable(dataSource, databaseName, name);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
exports.MongoDBService = MongoDBService;
|
|
488
|
-
/**
|
|
489
|
-
* ObjectId 类型定义
|
|
490
|
-
*/
|
|
491
|
-
class ObjectId {
|
|
492
|
-
constructor(id) {
|
|
493
|
-
if (id) {
|
|
494
|
-
this.id = id;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
id;
|
|
498
|
-
toString() {
|
|
499
|
-
return this.id || '';
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
//# sourceMappingURL=mongodb.service.js.map
|