@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,181 @@
|
|
|
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 tables_exports = {};
|
|
38
|
+
__export(tables_exports, {
|
|
39
|
+
default: () => tables_default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(tables_exports);
|
|
42
|
+
var import_database = require("@nocobase/database");
|
|
43
|
+
var import_lodash = __toESM(require("lodash"));
|
|
44
|
+
async function getServerInstanceFromRequest(ctx) {
|
|
45
|
+
const { resourceOf } = ctx.action;
|
|
46
|
+
const serverInstance = await ctx.db.getRepository("databaseServers").findOne({
|
|
47
|
+
filterByTk: resourceOf
|
|
48
|
+
});
|
|
49
|
+
if (!serverInstance) {
|
|
50
|
+
throw new Error(`server ${resourceOf} not found`);
|
|
51
|
+
}
|
|
52
|
+
serverInstance.setApp(ctx.app);
|
|
53
|
+
return serverInstance;
|
|
54
|
+
}
|
|
55
|
+
async function splitNameToNameWithSchema(tableNameString) {
|
|
56
|
+
if (!tableNameString.includes(".")) {
|
|
57
|
+
return {
|
|
58
|
+
tableName: tableNameString
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const [schema, tableName] = tableNameString.split(".");
|
|
62
|
+
return {
|
|
63
|
+
schema,
|
|
64
|
+
tableName
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function guessTableSequelizeAttribute(fields) {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
function columnAttribute(columnsInfo, columnName, indexes) {
|
|
71
|
+
const columnInfo = columnsInfo[columnName];
|
|
72
|
+
const attr = {
|
|
73
|
+
type: columnInfo.type,
|
|
74
|
+
allowNull: columnInfo.allowNull,
|
|
75
|
+
primaryKey: columnInfo.primaryKey,
|
|
76
|
+
unique: false
|
|
77
|
+
};
|
|
78
|
+
if (columnInfo.defaultValue && typeof columnInfo.defaultValue === "string") {
|
|
79
|
+
const isSerial = columnInfo.defaultValue.match(/^nextval\(/);
|
|
80
|
+
const isUUID = columnInfo.defaultValue.match(/^uuid_generate_v4\(/);
|
|
81
|
+
if (!isSerial && !isUUID) {
|
|
82
|
+
attr.defaultValue = columnInfo.defaultValue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const index of indexes) {
|
|
86
|
+
if (index.fields.length == 1 && index.fields[0].attribute == columnName && index.unique) {
|
|
87
|
+
attr.unique = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (attr.primaryKey && columnName == "id") {
|
|
91
|
+
attr.autoIncrement = true;
|
|
92
|
+
}
|
|
93
|
+
return attr;
|
|
94
|
+
}
|
|
95
|
+
var tables_default = {
|
|
96
|
+
name: "databaseServers.tables",
|
|
97
|
+
actions: {
|
|
98
|
+
// list tables on remote server
|
|
99
|
+
async list(ctx, next) {
|
|
100
|
+
const serverInstance = await getServerInstanceFromRequest(ctx);
|
|
101
|
+
serverInstance.setApp(ctx.app);
|
|
102
|
+
ctx.body = await serverInstance.listRemoteTables();
|
|
103
|
+
await next();
|
|
104
|
+
},
|
|
105
|
+
// get remote table columns
|
|
106
|
+
async get(ctx, next) {
|
|
107
|
+
const serverInstance = await getServerInstanceFromRequest(ctx);
|
|
108
|
+
serverInstance.setApp(ctx.app);
|
|
109
|
+
const tableName = ctx.action.params.filterByTk;
|
|
110
|
+
const tableInfo = await splitNameToNameWithSchema(tableName);
|
|
111
|
+
const tableColumns = await serverInstance.describeTable(tableInfo);
|
|
112
|
+
const indexes = await serverInstance.showIndexes(tableInfo);
|
|
113
|
+
const unsupportedFields = [];
|
|
114
|
+
const fields = [];
|
|
115
|
+
import_lodash.default.forEach(tableColumns, (column, key) => {
|
|
116
|
+
const columnInfo = {
|
|
117
|
+
...columnAttribute(tableColumns, key, indexes),
|
|
118
|
+
...import_database.ViewFieldInference.inferToFieldType({
|
|
119
|
+
dialect: serverInstance.get("dialect"),
|
|
120
|
+
type: column.type,
|
|
121
|
+
name: key
|
|
122
|
+
}),
|
|
123
|
+
name: key,
|
|
124
|
+
rawType: tableColumns[key].type
|
|
125
|
+
};
|
|
126
|
+
if (columnInfo.type) {
|
|
127
|
+
fields.push(columnInfo);
|
|
128
|
+
} else {
|
|
129
|
+
unsupportedFields.push(columnInfo);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const tableOptions = {
|
|
133
|
+
fields,
|
|
134
|
+
unsupportedFields
|
|
135
|
+
};
|
|
136
|
+
tableOptions.options = guessTableSequelizeAttribute(tableOptions.fields);
|
|
137
|
+
ctx.body = tableOptions;
|
|
138
|
+
await next();
|
|
139
|
+
},
|
|
140
|
+
async query(ctx, next) {
|
|
141
|
+
const { filterByTk, fieldTypes, schema = "public", page = 1, pageSize = 10 } = ctx.action.params;
|
|
142
|
+
const serverInstance = await getServerInstanceFromRequest(ctx);
|
|
143
|
+
serverInstance.setApp(ctx.app);
|
|
144
|
+
const tableInfo = await splitNameToNameWithSchema(filterByTk);
|
|
145
|
+
const offset = (page - 1) * pageSize;
|
|
146
|
+
const limit = 1 * pageSize;
|
|
147
|
+
const sql = `SELECT *
|
|
148
|
+
FROM ${ctx.app.db.utils.quoteTable(
|
|
149
|
+
ctx.app.db.utils.addSchema(tableInfo["tableName"], tableInfo["schema"])
|
|
150
|
+
)} LIMIT ${limit}
|
|
151
|
+
OFFSET ${offset}`;
|
|
152
|
+
const remoteDB = serverInstance.getRemoteDatabaseInstance();
|
|
153
|
+
const rawValues = await remoteDB.sequelize.query(sql, { type: "SELECT" });
|
|
154
|
+
await remoteDB.close();
|
|
155
|
+
if (fieldTypes) {
|
|
156
|
+
for (const raw of rawValues) {
|
|
157
|
+
const fakeInstance = {
|
|
158
|
+
dataValues: raw,
|
|
159
|
+
getDataValue: (key) => raw[key]
|
|
160
|
+
};
|
|
161
|
+
for (const fieldName of Object.keys(fieldTypes)) {
|
|
162
|
+
const fieldType = fieldTypes[fieldName];
|
|
163
|
+
const FieldClass = ctx.app.db.fieldTypes.get(fieldType);
|
|
164
|
+
const fieldOptions = new FieldClass(
|
|
165
|
+
{ name: fieldName },
|
|
166
|
+
{
|
|
167
|
+
db: ctx.app.db
|
|
168
|
+
}
|
|
169
|
+
).options;
|
|
170
|
+
if (fieldOptions.get) {
|
|
171
|
+
const newValue = fieldOptions.get.apply(fakeInstance);
|
|
172
|
+
raw[fieldName] = newValue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
ctx.body = rawValues;
|
|
178
|
+
await next();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-collection-fdw",
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"main": "./dist/server/index.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Collections"
|
|
7
|
+
],
|
|
8
|
+
"displayName": "Collection: Connect to foreign data (FDW)",
|
|
9
|
+
"displayName.zh-CN": "数据表:连接外部数据(FDW)",
|
|
10
|
+
"description": "Database-based foreign data wrapper (FDW) implementation for connecting to remote data tables, currently supports MySQL and PostgreSQL databases.",
|
|
11
|
+
"description.zh-CN": "基于数据库的 foreign data wrapper(FDW) 实现的连接远程数据表,目前支持 MySQL 和 PostgreSQL 数据库。",
|
|
12
|
+
"homepage": "https://docs.nocobase.com/handbook/collection-fdw",
|
|
13
|
+
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/collection-fdw",
|
|
14
|
+
"nocobase": {
|
|
15
|
+
"supportedVersions": [
|
|
16
|
+
"1.x",
|
|
17
|
+
"2.x"
|
|
18
|
+
],
|
|
19
|
+
"editionLevel": 0
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@ant-design/icons": "^5.1.4",
|
|
23
|
+
"@types/pg": "^8.10.9",
|
|
24
|
+
"mysql2": "^3.11.0",
|
|
25
|
+
"node-sql-parser": "^4.11.0",
|
|
26
|
+
"pg": "^8.11.3",
|
|
27
|
+
"pg-hstore": "^2.3.4",
|
|
28
|
+
"pg-types": "^2.1.0",
|
|
29
|
+
"sequelize": "^6.35.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@nocobase/client": "2.x",
|
|
33
|
+
"@nocobase/database": "2.x",
|
|
34
|
+
"@nocobase/server": "2.x",
|
|
35
|
+
"@nocobase/test": "2.x"
|
|
36
|
+
},
|
|
37
|
+
"volta": {
|
|
38
|
+
"node": "18.18.2",
|
|
39
|
+
"yarn": "1.22.21"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "5bcb42fc092f85adb9511c1a351b388bd7aaf66e",
|
|
42
|
+
"license": "Apache-2.0"
|
|
43
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|