@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,38 @@
|
|
|
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 mariadb_to_mariadb_exports = {};
|
|
28
|
+
__export(mariadb_to_mariadb_exports, {
|
|
29
|
+
MariadbToMariadbBridge: () => MariadbToMariadbBridge
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(mariadb_to_mariadb_exports);
|
|
32
|
+
var import_mysql_to_mysql = require("./mysql-to-mysql");
|
|
33
|
+
class MariadbToMariadbBridge extends import_mysql_to_mysql.MySQLToMySQLBridge {
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
MariadbToMariadbBridge
|
|
38
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { CreateServerOptions, CreateTableOptions, RemoteLocalBridge } from './remote-local-bridge';
|
|
10
|
+
export declare class MySQLToMySQLBridge extends RemoteLocalBridge {
|
|
11
|
+
createServer(options: CreateServerOptions): Promise<void>;
|
|
12
|
+
createTable(options: CreateTableOptions): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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 mysql_to_mysql_exports = {};
|
|
38
|
+
__export(mysql_to_mysql_exports, {
|
|
39
|
+
MySQLToMySQLBridge: () => MySQLToMySQLBridge
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(mysql_to_mysql_exports);
|
|
42
|
+
var import_node_sql_parser = require("node-sql-parser");
|
|
43
|
+
var import_remote_local_bridge = require("./remote-local-bridge");
|
|
44
|
+
var import_lodash = __toESM(require("lodash"));
|
|
45
|
+
class MySQLToMySQLBridge extends import_remote_local_bridge.RemoteLocalBridge {
|
|
46
|
+
async createServer(options) {
|
|
47
|
+
const { transaction } = options;
|
|
48
|
+
const servers = await this.localDatabase.sequelize.query(
|
|
49
|
+
"SELECT * FROM mysql.servers WHERE `Server_name` = :serverName",
|
|
50
|
+
{
|
|
51
|
+
replacements: { serverName: options.serverName },
|
|
52
|
+
transaction,
|
|
53
|
+
type: "SELECT"
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
if (servers.length) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
await this.localDatabase.sequelize.query(
|
|
60
|
+
`
|
|
61
|
+
CREATE SERVER '${options.serverName}'
|
|
62
|
+
FOREIGN DATA WRAPPER mysql
|
|
63
|
+
OPTIONS (USER :user, HOST :host, PORT ${options.port}, DATABASE :database, PASSWORD :password);
|
|
64
|
+
`,
|
|
65
|
+
{
|
|
66
|
+
replacements: { ...options },
|
|
67
|
+
transaction
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
async createTable(options) {
|
|
72
|
+
const { remoteTableInfo, transaction, localModel, remoteServerName } = options;
|
|
73
|
+
await this.localDatabase.sequelize.query(`DROP TABLE IF EXISTS ${localModel.tableName}`, {
|
|
74
|
+
transaction
|
|
75
|
+
});
|
|
76
|
+
let { remoteTableDefinition } = options;
|
|
77
|
+
if (remoteTableDefinition) {
|
|
78
|
+
remoteTableDefinition = this.replaceTableName(remoteTableDefinition, localModel.tableName);
|
|
79
|
+
}
|
|
80
|
+
const parser = new import_node_sql_parser.Parser();
|
|
81
|
+
const ast = parser.astify(remoteTableDefinition, {
|
|
82
|
+
database: "MySQL"
|
|
83
|
+
});
|
|
84
|
+
ast.table_options = [
|
|
85
|
+
{ keyword: "engine", symbol: "=", value: "FEDERATED" },
|
|
86
|
+
{
|
|
87
|
+
keyword: "default charset",
|
|
88
|
+
symbol: "=",
|
|
89
|
+
value: (() => {
|
|
90
|
+
const existCharset = ast.table_options.find((tableOpt) => tableOpt.keyword === "default charset");
|
|
91
|
+
if (existCharset) {
|
|
92
|
+
return existCharset.value;
|
|
93
|
+
}
|
|
94
|
+
return "utf8mb4";
|
|
95
|
+
})()
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
keyword: "connection",
|
|
99
|
+
symbol: "=",
|
|
100
|
+
value: `'${remoteServerName}/${remoteTableInfo.tableName}'`
|
|
101
|
+
}
|
|
102
|
+
];
|
|
103
|
+
ast.create_definitions = ast.create_definitions.map((def) => {
|
|
104
|
+
return import_lodash.default.omit(def, ["collate", "character_set"]);
|
|
105
|
+
});
|
|
106
|
+
const sql = parser.sqlify(ast, {
|
|
107
|
+
database: "MySQL"
|
|
108
|
+
});
|
|
109
|
+
await this.localDatabase.sequelize.query(sql, {
|
|
110
|
+
transaction
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
MySQLToMySQLBridge
|
|
117
|
+
});
|
|
@@ -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 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
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
* This file is part of the NocoBase (R) project.
|
|
11
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
12
|
+
* Authors: NocoBase Team.
|
|
13
|
+
*
|
|
14
|
+
* This program is offered under a commercial license.
|
|
15
|
+
* For more information, see <https://www.nocobase.com/agreement>
|
|
16
|
+
*/
|
|
17
|
+
import { CreateServerOptions, CreateTableOptions, RemoteLocalBridge } from './remote-local-bridge';
|
|
18
|
+
export declare class PgToPgBridge extends RemoteLocalBridge {
|
|
19
|
+
createServer(options: CreateServerOptions): Promise<void>;
|
|
20
|
+
createTable(options: CreateTableOptions): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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 pg_to_pg_exports = {};
|
|
28
|
+
__export(pg_to_pg_exports, {
|
|
29
|
+
PgToPgBridge: () => PgToPgBridge
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(pg_to_pg_exports);
|
|
32
|
+
var import_remote_local_bridge = require("./remote-local-bridge");
|
|
33
|
+
class PgToPgBridge extends import_remote_local_bridge.RemoteLocalBridge {
|
|
34
|
+
async createServer(options) {
|
|
35
|
+
const { transaction } = options;
|
|
36
|
+
const servers = await this.localDatabase.sequelize.query(
|
|
37
|
+
`SELECT * FROM pg_foreign_server WHERE srvname = :serverName`,
|
|
38
|
+
{
|
|
39
|
+
replacements: { serverName: options.serverName },
|
|
40
|
+
transaction,
|
|
41
|
+
type: "SELECT"
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
if (servers.length) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
await this.localDatabase.sequelize.query(
|
|
48
|
+
`
|
|
49
|
+
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
|
|
50
|
+
|
|
51
|
+
CREATE SERVER IF NOT EXISTS "${options.serverName}"
|
|
52
|
+
FOREIGN DATA WRAPPER postgres_fdw
|
|
53
|
+
OPTIONS (host :host, port :port, dbname :database);
|
|
54
|
+
|
|
55
|
+
CREATE USER MAPPING IF NOT EXISTS FOR "${this.localDatabase.options.username}"
|
|
56
|
+
SERVER "${options.serverName}"
|
|
57
|
+
OPTIONS (user :user, password :password);
|
|
58
|
+
`,
|
|
59
|
+
{
|
|
60
|
+
replacements: { ...options },
|
|
61
|
+
transaction,
|
|
62
|
+
type: "RAW"
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
async createTable(options) {
|
|
67
|
+
const { remoteTableInfo, transaction, localModel, remoteServerName } = options;
|
|
68
|
+
let { remoteTableDefinition } = options;
|
|
69
|
+
await this.remoteDatabase.sequelize.query(
|
|
70
|
+
`
|
|
71
|
+
CREATE OR REPLACE FUNCTION handle_null_id()
|
|
72
|
+
RETURNS TRIGGER AS $$
|
|
73
|
+
DECLARE
|
|
74
|
+
sequence_name text;
|
|
75
|
+
schema_name text;
|
|
76
|
+
id_column_exists boolean;
|
|
77
|
+
BEGIN
|
|
78
|
+
SELECT INTO id_column_exists
|
|
79
|
+
EXISTS (
|
|
80
|
+
SELECT 1
|
|
81
|
+
FROM information_schema.columns
|
|
82
|
+
WHERE table_schema = (SELECT nspname FROM pg_namespace JOIN pg_class ON pg_class.relnamespace = pg_namespace.oid WHERE pg_class.oid = TG_RELID)
|
|
83
|
+
AND table_name = (SELECT relname FROM pg_class WHERE oid = TG_RELID)
|
|
84
|
+
AND column_name = 'id'
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
IF NOT id_column_exists THEN
|
|
88
|
+
RETURN NEW;
|
|
89
|
+
END IF;
|
|
90
|
+
|
|
91
|
+
SELECT INTO schema_name nspname FROM pg_namespace
|
|
92
|
+
JOIN pg_class ON pg_class.relnamespace = pg_namespace.oid
|
|
93
|
+
WHERE pg_class.oid = TG_RELID;
|
|
94
|
+
|
|
95
|
+
SELECT INTO sequence_name pg_get_serial_sequence(quote_ident(schema_name) || '.' || quote_ident(pg_class.relname), 'id')
|
|
96
|
+
FROM pg_class WHERE pg_class.oid = TG_RELID;
|
|
97
|
+
|
|
98
|
+
IF sequence_name IS NOT NULL AND NEW.id IS NULL THEN
|
|
99
|
+
NEW.id := nextval(sequence_name);
|
|
100
|
+
END IF;
|
|
101
|
+
|
|
102
|
+
RETURN NEW;
|
|
103
|
+
END;
|
|
104
|
+
$$ LANGUAGE plpgsql;
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
DROP TRIGGER IF EXISTS set_default_id ON "${remoteTableInfo.schema}"."${remoteTableInfo.tableName}";
|
|
108
|
+
|
|
109
|
+
CREATE TRIGGER set_default_id
|
|
110
|
+
BEFORE INSERT ON "${remoteTableInfo.schema}"."${remoteTableInfo.tableName}"
|
|
111
|
+
FOR EACH ROW
|
|
112
|
+
EXECUTE PROCEDURE handle_null_id();
|
|
113
|
+
`,
|
|
114
|
+
{
|
|
115
|
+
type: "RAW"
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
await this.localDatabase.sequelize.query(
|
|
119
|
+
`DROP FOREIGN TABLE IF EXISTS ${localModel.collection.quotedTableName()}`,
|
|
120
|
+
{
|
|
121
|
+
transaction
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
remoteTableDefinition = this.replaceTableName(remoteTableDefinition, localModel.collection.quotedTableName());
|
|
125
|
+
remoteTableDefinition = remoteTableDefinition.replace("CREATE TABLE", "CREATE FOREIGN TABLE");
|
|
126
|
+
remoteTableDefinition = remoteTableDefinition.replace(";", "");
|
|
127
|
+
remoteTableDefinition = remoteTableDefinition.replace(/\bNOT NULL\b/g, "");
|
|
128
|
+
remoteTableDefinition = `${remoteTableDefinition} SERVER "${remoteServerName}" OPTIONS (schema_name '${remoteTableInfo.schema}', table_name '${remoteTableInfo.tableName}')`;
|
|
129
|
+
await this.localDatabase.sequelize.query(remoteTableDefinition, {
|
|
130
|
+
transaction
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
PgToPgBridge
|
|
137
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
* This file is part of the NocoBase (R) project.
|
|
11
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
12
|
+
* Authors: NocoBase Team.
|
|
13
|
+
*
|
|
14
|
+
* This program is offered under a commercial license.
|
|
15
|
+
* For more information, see <https://www.nocobase.com/agreement>
|
|
16
|
+
*/
|
|
17
|
+
import { Database, Model } from '@nocobase/database';
|
|
18
|
+
import { Transactionable } from 'sequelize';
|
|
19
|
+
type RemoteDialect = 'postgres' | 'mysql' | 'mariadb';
|
|
20
|
+
export type TableInfo = {
|
|
21
|
+
schema?: string;
|
|
22
|
+
tableName: string;
|
|
23
|
+
};
|
|
24
|
+
export type CreateServerOptions = {
|
|
25
|
+
serverName: string;
|
|
26
|
+
host: string;
|
|
27
|
+
port: number;
|
|
28
|
+
database: string;
|
|
29
|
+
user: string;
|
|
30
|
+
password: string;
|
|
31
|
+
} & Transactionable;
|
|
32
|
+
export type CreateTableOptions = {
|
|
33
|
+
remoteServerName: string;
|
|
34
|
+
remoteTableDefinition: string;
|
|
35
|
+
remoteTableInfo: TableInfo;
|
|
36
|
+
localModel: typeof Model;
|
|
37
|
+
} & Transactionable;
|
|
38
|
+
export declare const REPLACE_TABLE_NAME_REGEX: RegExp;
|
|
39
|
+
export declare abstract class RemoteLocalBridge {
|
|
40
|
+
protected localDatabase: Database;
|
|
41
|
+
protected remoteDatabase: Database;
|
|
42
|
+
constructor(localDatabase: Database, remoteDatabase: Database);
|
|
43
|
+
abstract createServer(options: CreateServerOptions): Promise<void>;
|
|
44
|
+
abstract createTable(options: CreateTableOptions): Promise<void>;
|
|
45
|
+
protected replaceTableName(sql: string, tableName: string): string;
|
|
46
|
+
}
|
|
47
|
+
interface CreateBridgeOptions {
|
|
48
|
+
remoteDatabase: Database;
|
|
49
|
+
localDatabase: Database;
|
|
50
|
+
}
|
|
51
|
+
export declare class RemoteLocalBridgeFactory {
|
|
52
|
+
static bridges: Map<string, typeof RemoteLocalBridge>;
|
|
53
|
+
static getKeyOfTuple(remoteDialect: RemoteDialect, localDialect: RemoteDialect): string;
|
|
54
|
+
static createBridge(options: CreateBridgeOptions): RemoteLocalBridge;
|
|
55
|
+
static registerBridge(remoteDialect: RemoteDialect, localDialect: RemoteDialect, bridge: typeof RemoteLocalBridge): void;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
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 remote_local_bridge_exports = {};
|
|
28
|
+
__export(remote_local_bridge_exports, {
|
|
29
|
+
REPLACE_TABLE_NAME_REGEX: () => REPLACE_TABLE_NAME_REGEX,
|
|
30
|
+
RemoteLocalBridge: () => RemoteLocalBridge,
|
|
31
|
+
RemoteLocalBridgeFactory: () => RemoteLocalBridgeFactory
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(remote_local_bridge_exports);
|
|
34
|
+
const IDENTIFIER_REGEX = String.raw`(?:[\`"'](?:(?![\`"']).)+[\`"']|[a-zA-Z0-9_-]+)`;
|
|
35
|
+
const REPLACE_TABLE_NAME_REGEX = new RegExp(
|
|
36
|
+
String.raw`CREATE TABLE\s+((?:${IDENTIFIER_REGEX})(?:\.(?:${IDENTIFIER_REGEX}))*)`
|
|
37
|
+
);
|
|
38
|
+
class RemoteLocalBridge {
|
|
39
|
+
localDatabase;
|
|
40
|
+
remoteDatabase;
|
|
41
|
+
constructor(localDatabase, remoteDatabase) {
|
|
42
|
+
this.localDatabase = localDatabase;
|
|
43
|
+
this.remoteDatabase = remoteDatabase;
|
|
44
|
+
}
|
|
45
|
+
replaceTableName(sql, tableName) {
|
|
46
|
+
return sql.replace(REPLACE_TABLE_NAME_REGEX, `CREATE TABLE ${tableName}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class RemoteLocalBridgeFactory {
|
|
50
|
+
static bridges = /* @__PURE__ */ new Map();
|
|
51
|
+
static getKeyOfTuple(remoteDialect, localDialect) {
|
|
52
|
+
return `${remoteDialect}-${localDialect}`;
|
|
53
|
+
}
|
|
54
|
+
static createBridge(options) {
|
|
55
|
+
const { remoteDatabase, localDatabase } = options;
|
|
56
|
+
const remoteDialect = remoteDatabase.options.dialect;
|
|
57
|
+
const localDialect = localDatabase.options.dialect;
|
|
58
|
+
const bridge = this.bridges.get(this.getKeyOfTuple(remoteDialect, localDialect));
|
|
59
|
+
if (!bridge) {
|
|
60
|
+
throw new Error(`bridge not found for ${remoteDialect} to ${localDialect}`);
|
|
61
|
+
}
|
|
62
|
+
return new bridge(localDatabase, remoteDatabase);
|
|
63
|
+
}
|
|
64
|
+
static registerBridge(remoteDialect, localDialect, bridge) {
|
|
65
|
+
this.bridges.set(this.getKeyOfTuple(remoteDialect, localDialect), bridge);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
REPLACE_TABLE_NAME_REGEX,
|
|
71
|
+
RemoteLocalBridge,
|
|
72
|
+
RemoteLocalBridgeFactory
|
|
73
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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: import("@nocobase/database").CollectionOptions;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 database_server_collection_exports = {};
|
|
28
|
+
__export(database_server_collection_exports, {
|
|
29
|
+
default: () => database_server_collection_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(database_server_collection_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var database_server_collection_default = (0, import_database.defineCollection)({
|
|
34
|
+
name: "databaseServers",
|
|
35
|
+
dumpRules: "required",
|
|
36
|
+
migrationRules: ["overwrite", "schema-only"],
|
|
37
|
+
autoGenId: false,
|
|
38
|
+
model: "DatabaseServerModel",
|
|
39
|
+
fields: [
|
|
40
|
+
{
|
|
41
|
+
type: "string",
|
|
42
|
+
name: "name",
|
|
43
|
+
primaryKey: true
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "string",
|
|
47
|
+
name: "description"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "json",
|
|
51
|
+
name: "options"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { Collection, CollectionContext, CollectionOptions, Model } from '@nocobase/database';
|
|
10
|
+
import { QueryInterfaceDropTableOptions, QueryInterfaceOptions } from 'sequelize';
|
|
11
|
+
import PluginCollectionFDWServer from './plugin';
|
|
12
|
+
export declare class ForeignDataCollection extends Collection {
|
|
13
|
+
constructor(options: CollectionOptions, context: CollectionContext);
|
|
14
|
+
static registerOptions(plugin: PluginCollectionFDWServer): {
|
|
15
|
+
condition(options: any): any;
|
|
16
|
+
onDump(): Promise<void>;
|
|
17
|
+
onSync(model: typeof Model, options: any): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
removeFieldFromDb(name: string, options?: QueryInterfaceOptions): Promise<void>;
|
|
20
|
+
removeFromDb(options?: QueryInterfaceDropTableOptions): Promise<Collection<any, any>>;
|
|
21
|
+
protected bindFieldEventListener(): void;
|
|
22
|
+
}
|