plugin-data-source-postgres 2.0.0 → 2.1.1
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 +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/constants.js +3 -0
- package/dist/externalVersion.js +10 -8
- package/dist/locale/en-US.json +8 -1
- package/dist/locale/zh-CN.json +8 -1
- package/dist/server/collections/sql-collection.js +2 -2
- package/dist/server/collections/sql-model.js +4 -2
- package/dist/server/hooks/field-hooks.js +20 -0
- package/dist/server/plugin.js +727 -23
- package/dist/server/postgres-collection-manager.js +192 -25
- package/dist/server/postgres-datasource.js +47 -13
- package/dist/server/utils/sql-validator.js +119 -69
- package/package.json +2 -2
- package/src/client/ConfigurationForm.tsx +312 -133
- package/src/client/__tests__/client-v1.test.tsx +80 -0
- package/src/client-v2/PostgresConfigForm.tsx +133 -6
- package/src/client-v2/__tests__/plugin.test.tsx +69 -0
- package/src/client-v2/plugin.tsx +2 -2
- package/src/constants.ts +15 -0
- package/src/locale/en-US.json +8 -1
- package/src/locale/zh-CN.json +8 -1
- package/src/server/__tests__/postgres-datasource.unit.test.ts +1038 -0
- package/src/server/__tests__/sql-model.test.ts +47 -3
- package/src/server/__tests__/sql-validator.test.ts +8 -1
- package/src/server/collections/sql-collection.ts +2 -2
- package/src/server/collections/sql-model.ts +2 -2
- package/src/server/hooks/field-hooks.ts +36 -2
- package/src/server/plugin.ts +912 -18
- package/src/server/postgres-collection-manager.ts +228 -28
- package/src/server/postgres-datasource.ts +57 -12
- package/src/server/utils/sql-validator.ts +123 -68
- package/dist/client-v2/985.34da95acdf7743ab.js +0 -10
package/dist/locale/en-US.json
CHANGED
|
@@ -137,5 +137,12 @@
|
|
|
137
137
|
"Column name": "Column name",
|
|
138
138
|
"Column name is required": "Column name is required",
|
|
139
139
|
"Foreign key {{foreignKey}} cannot have the same name as relation field {{name}}": "Foreign key {{foreignKey}} cannot have the same name as relation field {{name}}",
|
|
140
|
-
"Foreign key {{collection}}.{{field}} has incompatible PostgreSQL type {{type}}": "Foreign key {{collection}}.{{field}} has incompatible PostgreSQL type {{type}}"
|
|
140
|
+
"Foreign key {{collection}}.{{field}} has incompatible PostgreSQL type {{type}}": "Foreign key {{collection}}.{{field}} has incompatible PostgreSQL type {{type}}",
|
|
141
|
+
"Saved connection": "Saved connection",
|
|
142
|
+
"Reuse an existing PostgreSQL connection or leave blank to create a new one": "Reuse an existing PostgreSQL connection or leave blank to create a new one",
|
|
143
|
+
"Create new connection": "Create new connection",
|
|
144
|
+
"Leave blank to reuse saved password": "Leave blank to reuse saved password",
|
|
145
|
+
"Leave blank to reuse saved CA certificate": "Leave blank to reuse saved CA certificate",
|
|
146
|
+
"Saved PostgreSQL connection {{name}} does not exist": "Saved PostgreSQL connection {{name}} does not exist",
|
|
147
|
+
"No saved PostgreSQL connections": "No saved PostgreSQL connections"
|
|
141
148
|
}
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -137,5 +137,12 @@
|
|
|
137
137
|
"Column name": "列名",
|
|
138
138
|
"Column name is required": "请输入列名",
|
|
139
139
|
"Foreign key {{foreignKey}} cannot have the same name as relation field {{name}}": "外键 {{foreignKey}} 不能与关系字段 {{name}} 同名",
|
|
140
|
-
"Foreign key {{collection}}.{{field}} has incompatible PostgreSQL type {{type}}": "外键 {{collection}}.{{field}} 的 PostgreSQL 类型 {{type}} 不兼容"
|
|
140
|
+
"Foreign key {{collection}}.{{field}} has incompatible PostgreSQL type {{type}}": "外键 {{collection}}.{{field}} 的 PostgreSQL 类型 {{type}} 不兼容",
|
|
141
|
+
"Saved connection": "已保存的连接",
|
|
142
|
+
"Reuse an existing PostgreSQL connection or leave blank to create a new one": "复用已有的 PostgreSQL 连接,或留空以创建新连接",
|
|
143
|
+
"Create new connection": "创建新连接",
|
|
144
|
+
"Leave blank to reuse saved password": "留空以复用已保存的密码",
|
|
145
|
+
"Leave blank to reuse saved CA certificate": "留空以复用已保存的 CA 证书",
|
|
146
|
+
"Saved PostgreSQL connection {{name}} does not exist": "已保存的 PostgreSQL 连接 {{name}} 不存在",
|
|
147
|
+
"No saved PostgreSQL connections": "暂无已保存的 PostgreSQL 连接"
|
|
141
148
|
}
|
|
@@ -30,6 +30,7 @@ __export(sql_collection_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(sql_collection_exports);
|
|
32
32
|
var import_database = require("@nocobase/database");
|
|
33
|
+
var import_sql_validator = require("../utils/sql-validator");
|
|
33
34
|
var import_sql_model = require("./sql-model");
|
|
34
35
|
class PostgresSQLCollection extends import_database.Collection {
|
|
35
36
|
constructor(options, context) {
|
|
@@ -54,8 +55,7 @@ class PostgresSQLCollection extends import_database.Collection {
|
|
|
54
55
|
return void 0;
|
|
55
56
|
}
|
|
56
57
|
modelInit() {
|
|
57
|
-
const
|
|
58
|
-
const normalizedSql = sql.endsWith(";") ? sql.slice(0, -1) : sql;
|
|
58
|
+
const normalizedSql = (0, import_sql_validator.normalizeSqlCollectionQuery)(String(this.options.sql || ""));
|
|
59
59
|
if (this.model) {
|
|
60
60
|
this.model.sql = normalizedSql;
|
|
61
61
|
return;
|
|
@@ -36,7 +36,8 @@ var import_validation_error = require("../utils/validation-error");
|
|
|
36
36
|
function selectQuery(_tableName, options, model) {
|
|
37
37
|
var _a;
|
|
38
38
|
const queryOptions = options || {};
|
|
39
|
-
if ((0, import_lodash.isEmpty)(queryOptions)) return `${model.sql}
|
|
39
|
+
if ((0, import_lodash.isEmpty)(queryOptions)) return `${model.sql}
|
|
40
|
+
;`;
|
|
40
41
|
let attributes = (_a = queryOptions.attributes) == null ? void 0 : _a.slice();
|
|
41
42
|
if (attributes) {
|
|
42
43
|
const fields = Array.from(model.collection.fields.keys());
|
|
@@ -63,7 +64,8 @@ function selectQuery(_tableName, options, model) {
|
|
|
63
64
|
}
|
|
64
65
|
const limit = this.addLimitAndOffset(queryOptions, model);
|
|
65
66
|
if (limit) clauses.push(limit);
|
|
66
|
-
return `SELECT ${selected.join(", ")} FROM (${model.sql}
|
|
67
|
+
return `SELECT ${selected.join(", ")} FROM (${model.sql}
|
|
68
|
+
) ${this.getAliasToken()} ${this.quoteIdentifier(
|
|
67
69
|
model.name
|
|
68
70
|
)}${clauses.join("")};`;
|
|
69
71
|
}
|
|
@@ -35,6 +35,7 @@ __export(field_hooks_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(field_hooks_exports);
|
|
36
36
|
var import_sequelize = require("sequelize");
|
|
37
37
|
var import_lodash = require("lodash");
|
|
38
|
+
var import_postgres_collection_manager = require("../postgres-collection-manager");
|
|
38
39
|
var import_validation_error = require("../utils/validation-error");
|
|
39
40
|
const RELATION_TYPES = /* @__PURE__ */ new Set(["belongsTo", "belongsToMany", "belongsToArray", "hasOne", "hasMany"]);
|
|
40
41
|
const RELATION_INTERFACES = {
|
|
@@ -326,6 +327,13 @@ async function syncFieldAction(manager, action, collectionName, fieldName, input
|
|
|
326
327
|
await ensureBelongsToArray(manager, collectionName, name, values, input, transaction);
|
|
327
328
|
return;
|
|
328
329
|
}
|
|
330
|
+
(0, import_postgres_collection_manager.applyPostgresArrayDataType)(values);
|
|
331
|
+
if (values.dataType === "array") {
|
|
332
|
+
input.dataType = "array";
|
|
333
|
+
if (input.elementType === void 0 && typeof values.elementType === "string") {
|
|
334
|
+
input.elementType = values.elementType;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
329
337
|
await manager.addField(collectionName, { ...values, name }, transaction);
|
|
330
338
|
return;
|
|
331
339
|
}
|
|
@@ -363,9 +371,21 @@ async function syncFieldAction(manager, action, collectionName, fieldName, input
|
|
|
363
371
|
}
|
|
364
372
|
return;
|
|
365
373
|
}
|
|
374
|
+
const effectiveType = values.type ?? field.options.type;
|
|
375
|
+
const effectiveElementType = values.elementType ?? field.options.elementType;
|
|
376
|
+
const effectiveDataType = values.dataType !== void 0 ? values.dataType : field.options.dataType;
|
|
377
|
+
if ((effectiveType === "array" || effectiveType === "set") && typeof effectiveElementType === "string" && effectiveElementType.trim().length > 0 && (effectiveDataType === void 0 || effectiveDataType === null || effectiveDataType === "")) {
|
|
378
|
+
const rawTypeIsArray = field.options.rawType === void 0 ? void 0 : (0, import_postgres_collection_manager.isPostgresPhysicalArrayRawType)(field.options.rawType);
|
|
379
|
+
const columnIsArray = rawTypeIsArray !== void 0 ? rawTypeIsArray : await manager.isPhysicalArrayColumn(collectionName, field.columnName(), transaction);
|
|
380
|
+
if (columnIsArray !== false) {
|
|
381
|
+
values.dataType = "array";
|
|
382
|
+
input.dataType = "array";
|
|
383
|
+
}
|
|
384
|
+
}
|
|
366
385
|
const changes = {};
|
|
367
386
|
for (const key of [
|
|
368
387
|
"type",
|
|
388
|
+
"dataType",
|
|
369
389
|
"allowNull",
|
|
370
390
|
"defaultValue",
|
|
371
391
|
"unique",
|