@nocobase/plugin-collection-fdw 2.0.3
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/LICENSE +201 -0
- package/README.md +99 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/07d37b2045cf49ac.js +10 -0
- package/dist/client/19796e1ee00c3777.js +10 -0
- package/dist/client/545679e3c044a8fb.js +10 -0
- package/dist/client/components/CreateDatabaseServerAction.d.ts +10 -0
- package/dist/client/components/DatabaseServerSelect.d.ts +20 -0
- package/dist/client/components/EditDatabaseServerAction.d.ts +10 -0
- package/dist/client/components/PreviewFields.d.ts +10 -0
- package/dist/client/components/PreviewTable.d.ts +10 -0
- package/dist/client/components/RemoteTableSelect.d.ts +10 -0
- package/dist/client/components/SyncFieldsAction.d.ts +11 -0
- package/dist/client/components/UnSupportFields.d.ts +12 -0
- package/dist/client/components/schema.d.ts +19 -0
- package/dist/client/dccc3127ba4bb534.js +10 -0
- package/dist/client/ff008086e5ac8e5e.js +10 -0
- package/dist/client/hooks.d.ts +20 -0
- package/dist/client/index.d.ts +13 -0
- package/dist/client/index.js +10 -0
- package/dist/externalVersion.js +24 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +42 -0
- package/dist/locale/de-DE.json +17 -0
- package/dist/locale/en-US.json +17 -0
- package/dist/locale/es-ES.json +17 -0
- package/dist/locale/fr-FR.json +17 -0
- package/dist/locale/hu-HU.json +17 -0
- package/dist/locale/id-ID.json +17 -0
- package/dist/locale/index.d.ts +10 -0
- package/dist/locale/index.js +42 -0
- package/dist/locale/it-IT.json +17 -0
- package/dist/locale/ja-JP.json +17 -0
- package/dist/locale/ko-KR.json +17 -0
- package/dist/locale/nl-NL.json +17 -0
- package/dist/locale/pt-BR.json +17 -0
- package/dist/locale/ru-RU.json +18 -0
- package/dist/locale/tr-TR.json +17 -0
- package/dist/locale/uk-UA.json +17 -0
- package/dist/locale/vi-VN.json +17 -0
- package/dist/locale/zh-CN.json +17 -0
- package/dist/locale/zh-TW.json +17 -0
- package/dist/node_modules/node-sql-parser/LICENSE +201 -0
- package/dist/node_modules/node-sql-parser/ast/postgresql.ts +1834 -0
- package/dist/node_modules/node-sql-parser/build/bigquery.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/bigquery.js +2 -0
- package/dist/node_modules/node-sql-parser/build/db2.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/db2.js +2 -0
- package/dist/node_modules/node-sql-parser/build/flinksql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/flinksql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/hive.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/hive.js +2 -0
- package/dist/node_modules/node-sql-parser/build/mariadb.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/mariadb.js +2 -0
- package/dist/node_modules/node-sql-parser/build/mysql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/mysql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/noql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/noql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/postgresql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/postgresql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/snowflake.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/snowflake.js +2 -0
- package/dist/node_modules/node-sql-parser/build/sqlite.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/sqlite.js +2 -0
- package/dist/node_modules/node-sql-parser/build/transactsql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/transactsql.js +2 -0
- package/dist/node_modules/node-sql-parser/index.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/index.js +1 -0
- package/dist/node_modules/node-sql-parser/lib/aggregation.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/alter.js +174 -0
- package/dist/node_modules/node-sql-parser/lib/analyze.js +40 -0
- package/dist/node_modules/node-sql-parser/lib/array-struct.js +60 -0
- package/dist/node_modules/node-sql-parser/lib/assign.js +33 -0
- package/dist/node_modules/node-sql-parser/lib/binary.js +46 -0
- package/dist/node_modules/node-sql-parser/lib/case.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/column.js +221 -0
- package/dist/node_modules/node-sql-parser/lib/command.js +299 -0
- package/dist/node_modules/node-sql-parser/lib/constrain.js +45 -0
- package/dist/node_modules/node-sql-parser/lib/create.js +439 -0
- package/dist/node_modules/node-sql-parser/lib/delete.js +42 -0
- package/dist/node_modules/node-sql-parser/lib/exec.js +37 -0
- package/dist/node_modules/node-sql-parser/lib/expr.js +123 -0
- package/dist/node_modules/node-sql-parser/lib/func.js +152 -0
- package/dist/node_modules/node-sql-parser/lib/index-definition.js +106 -0
- package/dist/node_modules/node-sql-parser/lib/insert.js +111 -0
- package/dist/node_modules/node-sql-parser/lib/interval.js +28 -0
- package/dist/node_modules/node-sql-parser/lib/json.js +28 -0
- package/dist/node_modules/node-sql-parser/lib/limit.js +45 -0
- package/dist/node_modules/node-sql-parser/lib/over.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/parser.all.js +33 -0
- package/dist/node_modules/node-sql-parser/lib/parser.js +82 -0
- package/dist/node_modules/node-sql-parser/lib/parser.single.js +23 -0
- package/dist/node_modules/node-sql-parser/lib/proc.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/select.js +132 -0
- package/dist/node_modules/node-sql-parser/lib/show.js +88 -0
- package/dist/node_modules/node-sql-parser/lib/sql.js +43 -0
- package/dist/node_modules/node-sql-parser/lib/tables.js +211 -0
- package/dist/node_modules/node-sql-parser/lib/transaction.js +26 -0
- package/dist/node_modules/node-sql-parser/lib/union.js +81 -0
- package/dist/node_modules/node-sql-parser/lib/update.js +59 -0
- package/dist/node_modules/node-sql-parser/lib/util.js +444 -0
- package/dist/node_modules/node-sql-parser/lib/window.js +85 -0
- package/dist/node_modules/node-sql-parser/lib/with.js +37 -0
- package/dist/node_modules/node-sql-parser/package.json +1 -0
- package/dist/node_modules/node-sql-parser/types.d.ts +227 -0
- package/dist/node_modules/node-sql-parser/umd/bigquery.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/bigquery.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/db2.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/db2.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/flinksql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/flinksql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/hive.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/hive.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/index.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/index.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/mariadb.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/mariadb.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/mysql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/mysql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/noql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/noql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/postgresql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/postgresql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/snowflake.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/snowflake.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/sqlite.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/sqlite.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/transactsql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/transactsql.umd.js +2 -0
- package/dist/server/bridges/mariadb-to-mariadb.d.ts +3 -0
- package/dist/server/bridges/mariadb-to-mariadb.js +38 -0
- package/dist/server/bridges/mysql-to-mysql.d.ts +13 -0
- package/dist/server/bridges/mysql-to-mysql.js +117 -0
- package/dist/server/bridges/mysql-to-pg.d.ts +8 -0
- package/dist/server/bridges/mysql-to-pg.js +9 -0
- package/dist/server/bridges/pg-to-pg.d.ts +21 -0
- package/dist/server/bridges/pg-to-pg.js +137 -0
- package/dist/server/bridges/remote-local-bridge.d.ts +57 -0
- package/dist/server/bridges/remote-local-bridge.js +73 -0
- package/dist/server/collections/database-server-collection.d.ts +10 -0
- package/dist/server/collections/database-server-collection.js +54 -0
- package/dist/server/foreign-data-collection.d.ts +22 -0
- package/dist/server/foreign-data-collection.js +118 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +42 -0
- package/dist/server/models/database-server.d.ts +29 -0
- package/dist/server/models/database-server.js +226 -0
- package/dist/server/plugin.d.ts +14 -0
- package/dist/server/plugin.js +111 -0
- package/dist/server/resourcers/tables.d.ts +17 -0
- package/dist/server/resourcers/tables.js +181 -0
- package/package.json +43 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var foreign_data_collection_exports = {};
|
|
28
|
+
__export(foreign_data_collection_exports, {
|
|
29
|
+
ForeignDataCollection: () => ForeignDataCollection
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(foreign_data_collection_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var import_remote_local_bridge = require("./bridges/remote-local-bridge");
|
|
34
|
+
class ForeignDataCollection extends import_database.Collection {
|
|
35
|
+
constructor(options, context) {
|
|
36
|
+
if (!options.autoGenId) {
|
|
37
|
+
options.autoGenId = false;
|
|
38
|
+
}
|
|
39
|
+
if (!options.timestamps) {
|
|
40
|
+
options.timestamps = false;
|
|
41
|
+
}
|
|
42
|
+
options.underscored = false;
|
|
43
|
+
super(options, context);
|
|
44
|
+
}
|
|
45
|
+
static registerOptions(plugin) {
|
|
46
|
+
return {
|
|
47
|
+
condition(options) {
|
|
48
|
+
return options.remoteServerName && options.remoteTableInfo;
|
|
49
|
+
},
|
|
50
|
+
async onDump() {
|
|
51
|
+
return;
|
|
52
|
+
},
|
|
53
|
+
async onSync(model, options) {
|
|
54
|
+
const transaction = options == null ? void 0 : options.transaction;
|
|
55
|
+
const { remoteServerName, remoteTableInfo } = model.collection.options;
|
|
56
|
+
const remoteServerInstance = await model.database.getRepository("databaseServers").findOne({
|
|
57
|
+
filterByTk: remoteServerName,
|
|
58
|
+
transaction
|
|
59
|
+
});
|
|
60
|
+
if (!remoteServerInstance) {
|
|
61
|
+
throw new Error(`remoteServer ${remoteServerName} not found`);
|
|
62
|
+
}
|
|
63
|
+
remoteServerInstance.setApp(plugin.app);
|
|
64
|
+
await remoteServerInstance.createServer({
|
|
65
|
+
transaction
|
|
66
|
+
});
|
|
67
|
+
const remoteLocalBridge = import_remote_local_bridge.RemoteLocalBridgeFactory.createBridge({
|
|
68
|
+
remoteDatabase: remoteServerInstance.getRemoteDatabaseInstance(),
|
|
69
|
+
localDatabase: model.database
|
|
70
|
+
});
|
|
71
|
+
await remoteLocalBridge.createTable({
|
|
72
|
+
remoteServerName,
|
|
73
|
+
remoteTableDefinition: await remoteServerInstance.showTableDefinition(remoteTableInfo),
|
|
74
|
+
remoteTableInfo,
|
|
75
|
+
localModel: model,
|
|
76
|
+
transaction
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async removeFieldFromDb(name, options) {
|
|
82
|
+
const field = this.getField(name);
|
|
83
|
+
if (field) {
|
|
84
|
+
field.remove();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async removeFromDb(options) {
|
|
88
|
+
const transaction = options == null ? void 0 : options.transaction;
|
|
89
|
+
if (this.db.inDialect("postgres")) {
|
|
90
|
+
let sql = `DROP FOREIGN TABLE IF EXISTS ${this.getTableNameWithSchemaAsString()}`;
|
|
91
|
+
if (options == null ? void 0 : options.cascade) {
|
|
92
|
+
sql += " CASCADE";
|
|
93
|
+
}
|
|
94
|
+
await this.db.sequelize.query(sql, {
|
|
95
|
+
transaction
|
|
96
|
+
});
|
|
97
|
+
return this.remove();
|
|
98
|
+
} else {
|
|
99
|
+
await super.removeFromDb(options);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
bindFieldEventListener() {
|
|
103
|
+
super.bindFieldEventListener();
|
|
104
|
+
this.on("field.afterAdd", (field) => {
|
|
105
|
+
const interfaceOption = field.options.interface;
|
|
106
|
+
if (interfaceOption === "updatedAt") {
|
|
107
|
+
this.model._timestampAttributes.createdAt = field.name;
|
|
108
|
+
}
|
|
109
|
+
if (interfaceOption === "createdAt") {
|
|
110
|
+
this.model._timestampAttributes.updatedAt = field.name;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
ForeignDataCollection
|
|
118
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This program is offered under a commercial license.
|
|
7
|
+
* For more information, see <https://www.nocobase.com/agreement>
|
|
8
|
+
*/
|
|
9
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var server_exports = {};
|
|
38
|
+
__export(server_exports, {
|
|
39
|
+
default: () => import_plugin.default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(server_exports);
|
|
42
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This program is offered under a commercial license.
|
|
7
|
+
* For more information, see <https://www.nocobase.com/agreement>
|
|
8
|
+
*/
|
|
9
|
+
import Database, { MagicAttributeModel, Transactionable } from '@nocobase/database';
|
|
10
|
+
import { Application } from '@nocobase/server';
|
|
11
|
+
type TableInfo = {
|
|
12
|
+
tableName: string;
|
|
13
|
+
schema?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class DatabaseServerModel extends MagicAttributeModel {
|
|
16
|
+
protected app: Application;
|
|
17
|
+
setApp(app: Application): void;
|
|
18
|
+
renderJsonTemplate(options: any): any;
|
|
19
|
+
getRemoteDatabaseInstance(): Database;
|
|
20
|
+
getOptions(): any;
|
|
21
|
+
listRemoteTables(): Promise<[unknown[], unknown]>;
|
|
22
|
+
describeTable(table: TableInfo): Promise<import("sequelize").ColumnsDescription>;
|
|
23
|
+
showIndexes(table: TableInfo): Promise<object>;
|
|
24
|
+
showTableDefinition(tableInfo: TableInfo): Promise<any>;
|
|
25
|
+
updateServer(options?: Transactionable): Promise<void>;
|
|
26
|
+
destroyServer(options?: Transactionable): Promise<void>;
|
|
27
|
+
createServer(options?: Transactionable): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var database_server_exports = {};
|
|
38
|
+
__export(database_server_exports, {
|
|
39
|
+
DatabaseServerModel: () => DatabaseServerModel
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(database_server_exports);
|
|
42
|
+
var import_database = __toESM(require("@nocobase/database"));
|
|
43
|
+
var import_remote_local_bridge = require("../bridges/remote-local-bridge");
|
|
44
|
+
class DatabaseServerModel extends import_database.MagicAttributeModel {
|
|
45
|
+
app;
|
|
46
|
+
setApp(app) {
|
|
47
|
+
this.app = app;
|
|
48
|
+
}
|
|
49
|
+
renderJsonTemplate(options) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (!((_a = this.app) == null ? void 0 : _a.environment)) {
|
|
52
|
+
return options;
|
|
53
|
+
}
|
|
54
|
+
return this.app.environment.renderJsonTemplate(options);
|
|
55
|
+
}
|
|
56
|
+
getRemoteDatabaseInstance() {
|
|
57
|
+
return new import_database.default(
|
|
58
|
+
this.renderJsonTemplate({
|
|
59
|
+
...this.toJSON()
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
getOptions() {
|
|
64
|
+
return this.renderJsonTemplate({
|
|
65
|
+
...this.toJSON()
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async listRemoteTables() {
|
|
69
|
+
const remoteDB = this.getRemoteDatabaseInstance();
|
|
70
|
+
if (remoteDB.inDialect("postgres")) {
|
|
71
|
+
const results = await remoteDB.sequelize.query(
|
|
72
|
+
`
|
|
73
|
+
SELECT table_name as name, table_schema as schema
|
|
74
|
+
FROM information_schema.tables
|
|
75
|
+
WHERE table_schema NOT IN ('information_schema', 'pg_catalog')
|
|
76
|
+
`,
|
|
77
|
+
{
|
|
78
|
+
type: "SELECT"
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
await remoteDB.close();
|
|
82
|
+
return results;
|
|
83
|
+
} else {
|
|
84
|
+
const options = this.getOptions();
|
|
85
|
+
const results = await remoteDB.sequelize.query(
|
|
86
|
+
`
|
|
87
|
+
SELECT table_name as name
|
|
88
|
+
FROM information_schema.tables
|
|
89
|
+
WHERE table_schema = '${options.database}'
|
|
90
|
+
`,
|
|
91
|
+
{
|
|
92
|
+
type: "SELECT"
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
await remoteDB.close();
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async describeTable(table) {
|
|
100
|
+
const remoteDB = this.getRemoteDatabaseInstance();
|
|
101
|
+
const columns = await remoteDB.sequelize.getQueryInterface().describeTable(table);
|
|
102
|
+
await remoteDB.close();
|
|
103
|
+
return columns;
|
|
104
|
+
}
|
|
105
|
+
async showIndexes(table) {
|
|
106
|
+
const remoteDB = this.getRemoteDatabaseInstance();
|
|
107
|
+
const queryOptions = (() => {
|
|
108
|
+
if (remoteDB.inDialect("postgres")) {
|
|
109
|
+
return table;
|
|
110
|
+
}
|
|
111
|
+
return table.tableName;
|
|
112
|
+
})();
|
|
113
|
+
const constraints = await remoteDB.sequelize.getQueryInterface().showIndex(queryOptions);
|
|
114
|
+
await remoteDB.close();
|
|
115
|
+
return constraints;
|
|
116
|
+
}
|
|
117
|
+
async showTableDefinition(tableInfo) {
|
|
118
|
+
const remoteDB = this.getRemoteDatabaseInstance();
|
|
119
|
+
const def = await remoteDB.queryInterface.showTableDefinition(tableInfo);
|
|
120
|
+
await remoteDB.close();
|
|
121
|
+
return def;
|
|
122
|
+
}
|
|
123
|
+
async updateServer(options) {
|
|
124
|
+
const { transaction } = options;
|
|
125
|
+
const db = this.app.db;
|
|
126
|
+
const remoteInstance = this.getRemoteDatabaseInstance();
|
|
127
|
+
try {
|
|
128
|
+
await remoteInstance.sequelize.authenticate();
|
|
129
|
+
} catch (error) {
|
|
130
|
+
throw new Error(`Unable to connect to the remote database: ${error.message}`);
|
|
131
|
+
}
|
|
132
|
+
const replacements = this.renderJsonTemplate({
|
|
133
|
+
serverName: this.get("name"),
|
|
134
|
+
host: this.get("host"),
|
|
135
|
+
port: this.get("port"),
|
|
136
|
+
database: this.get("database"),
|
|
137
|
+
user: this.get("username"),
|
|
138
|
+
password: this.get("password")
|
|
139
|
+
});
|
|
140
|
+
if (db.inDialect("postgres")) {
|
|
141
|
+
await db.sequelize.query(
|
|
142
|
+
`
|
|
143
|
+
ALTER SERVER ${this.get("name")}
|
|
144
|
+
OPTIONS (SET host :host, SET port :port, SET dbname :database);
|
|
145
|
+
|
|
146
|
+
ALTER USER MAPPING FOR ${db.options.username}
|
|
147
|
+
SERVER ${this.get("name")}
|
|
148
|
+
OPTIONS (SET user :user, SET password :password);
|
|
149
|
+
`,
|
|
150
|
+
{
|
|
151
|
+
replacements,
|
|
152
|
+
type: "RAW",
|
|
153
|
+
transaction
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (db.inDialect("mysql", "mariadb")) {
|
|
158
|
+
await db.sequelize.query(
|
|
159
|
+
`
|
|
160
|
+
ALTER SERVER ${this.get("name")}
|
|
161
|
+
OPTIONS (USER :user, HOST :host, PORT ${replacements.port}, DATABASE :database, PASSWORD :password);
|
|
162
|
+
`,
|
|
163
|
+
{
|
|
164
|
+
replacements,
|
|
165
|
+
transaction
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async destroyServer(options) {
|
|
171
|
+
const { transaction } = options;
|
|
172
|
+
const db = this.app.db;
|
|
173
|
+
if (db.inDialect("postgres")) {
|
|
174
|
+
await db.sequelize.query(
|
|
175
|
+
`
|
|
176
|
+
DROP SERVER IF EXISTS ${this.get("name")} CASCADE;
|
|
177
|
+
`,
|
|
178
|
+
{
|
|
179
|
+
transaction,
|
|
180
|
+
type: "RAW"
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (db.inDialect("mysql", "mariadb")) {
|
|
185
|
+
await db.sequelize.query(
|
|
186
|
+
`
|
|
187
|
+
DROP SERVER IF EXISTS ${this.get("name")};
|
|
188
|
+
`,
|
|
189
|
+
{
|
|
190
|
+
transaction,
|
|
191
|
+
type: "RAW"
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async createServer(options) {
|
|
197
|
+
const { transaction } = options;
|
|
198
|
+
const db = this.app.db;
|
|
199
|
+
const remoteInstance = this.getRemoteDatabaseInstance();
|
|
200
|
+
try {
|
|
201
|
+
await remoteInstance.sequelize.authenticate();
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw new Error(`Unable to connect to the remote database: ${error.message}`);
|
|
204
|
+
}
|
|
205
|
+
const remoteLocalBridge = import_remote_local_bridge.RemoteLocalBridgeFactory.createBridge({
|
|
206
|
+
remoteDatabase: remoteInstance,
|
|
207
|
+
localDatabase: db
|
|
208
|
+
});
|
|
209
|
+
const opts = this.renderJsonTemplate({
|
|
210
|
+
serverName: this.get("name"),
|
|
211
|
+
host: this.get("host"),
|
|
212
|
+
port: this.get("port"),
|
|
213
|
+
database: this.get("database"),
|
|
214
|
+
user: this.get("username"),
|
|
215
|
+
password: this.get("password")
|
|
216
|
+
});
|
|
217
|
+
await remoteLocalBridge.createServer({
|
|
218
|
+
...opts,
|
|
219
|
+
transaction
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
224
|
+
0 && (module.exports = {
|
|
225
|
+
DatabaseServerModel
|
|
226
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This program is offered under a commercial license.
|
|
7
|
+
* For more information, see <https://www.nocobase.com/agreement>
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from '@nocobase/server';
|
|
10
|
+
export default class PluginCollectionFDWServer extends Plugin {
|
|
11
|
+
beforeLoad(): Promise<void>;
|
|
12
|
+
load(): Promise<void>;
|
|
13
|
+
beforeEnable(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var plugin_exports = {};
|
|
38
|
+
__export(plugin_exports, {
|
|
39
|
+
default: () => PluginCollectionFDWServer
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
42
|
+
var import_database = require("@nocobase/database");
|
|
43
|
+
var import_server = require("@nocobase/server");
|
|
44
|
+
var import_mariadb_to_mariadb = require("./bridges/mariadb-to-mariadb");
|
|
45
|
+
var import_mysql_to_mysql = require("./bridges/mysql-to-mysql");
|
|
46
|
+
var import_pg_to_pg = require("./bridges/pg-to-pg");
|
|
47
|
+
var import_remote_local_bridge = require("./bridges/remote-local-bridge");
|
|
48
|
+
var import_foreign_data_collection = require("./foreign-data-collection");
|
|
49
|
+
var import_database_server = require("./models/database-server");
|
|
50
|
+
var import_tables = __toESM(require("./resourcers/tables"));
|
|
51
|
+
class PluginCollectionFDWServer extends import_server.Plugin {
|
|
52
|
+
async beforeLoad() {
|
|
53
|
+
import_remote_local_bridge.RemoteLocalBridgeFactory.registerBridge("postgres", "postgres", import_pg_to_pg.PgToPgBridge);
|
|
54
|
+
import_remote_local_bridge.RemoteLocalBridgeFactory.registerBridge("mariadb", "mariadb", import_mariadb_to_mariadb.MariadbToMariadbBridge);
|
|
55
|
+
import_remote_local_bridge.RemoteLocalBridgeFactory.registerBridge("mysql", "mysql", import_mysql_to_mysql.MySQLToMySQLBridge);
|
|
56
|
+
const app = this.app;
|
|
57
|
+
this.app.db.registerModels({
|
|
58
|
+
DatabaseServerModel: import_database_server.DatabaseServerModel
|
|
59
|
+
});
|
|
60
|
+
this.app.db.on("databaseServers.beforeCreate", async (model, options) => {
|
|
61
|
+
if (!model.get("dialect")) {
|
|
62
|
+
const dialect = this.db.options.dialect;
|
|
63
|
+
model.set("dialect", dialect);
|
|
64
|
+
}
|
|
65
|
+
model.setApp(this.app);
|
|
66
|
+
await model.createServer(options);
|
|
67
|
+
});
|
|
68
|
+
this.app.db.on("databaseServers.afterUpdate", async (model, options) => {
|
|
69
|
+
model.setApp(this.app);
|
|
70
|
+
await model.updateServer(options);
|
|
71
|
+
});
|
|
72
|
+
this.app.db.on("databaseServers.afterDestroy", async (model, options) => {
|
|
73
|
+
model.setApp(this.app);
|
|
74
|
+
await model.destroyServer(options);
|
|
75
|
+
});
|
|
76
|
+
this.app.resourceManager.define(import_tables.default);
|
|
77
|
+
this.app.db.collectionFactory.registerCollectionType(
|
|
78
|
+
import_foreign_data_collection.ForeignDataCollection,
|
|
79
|
+
import_foreign_data_collection.ForeignDataCollection.registerOptions(this)
|
|
80
|
+
);
|
|
81
|
+
this.app.resourceManager.registerActionHandlers({
|
|
82
|
+
async ["databaseServers:testConnection"](ctx, next) {
|
|
83
|
+
const values = ctx.app.environment.renderJsonTemplate(ctx.action.params.values || {});
|
|
84
|
+
const db = new import_database.Database({
|
|
85
|
+
dialect: app.db.options.dialect,
|
|
86
|
+
...values
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
await db.sequelize.authenticate();
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw new Error(`Unable to connect to the remote database: ${error.message}`);
|
|
92
|
+
}
|
|
93
|
+
ctx.body = {
|
|
94
|
+
success: true
|
|
95
|
+
};
|
|
96
|
+
await next();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async load() {
|
|
101
|
+
this.app.acl.registerSnippet({
|
|
102
|
+
name: "pm.data-source-manager.collection-fdw",
|
|
103
|
+
actions: ["databaseServers:*", "databaseServers.tables:*"]
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async beforeEnable() {
|
|
107
|
+
if (this.db.inDialect("sqlite")) {
|
|
108
|
+
throw new Error("sqlite does not support foreign data wrapper");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This program is offered under a commercial license.
|
|
7
|
+
* For more information, see <https://www.nocobase.com/agreement>
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: {
|
|
10
|
+
name: string;
|
|
11
|
+
actions: {
|
|
12
|
+
list(ctx: any, next: any): Promise<void>;
|
|
13
|
+
get(ctx: any, next: any): Promise<void>;
|
|
14
|
+
query(ctx: any, next: any): Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|