@nocobase/database 1.4.0-alpha.20241025010959 → 1.4.0-alpha.20241031134640
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/lib/collection.d.ts +3 -1
- package/lib/collection.js +26 -4
- package/package.json +4 -4
package/lib/collection.d.ts
CHANGED
|
@@ -78,13 +78,13 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
78
78
|
repository: Repository<TModelAttributes, TCreationAttributes>;
|
|
79
79
|
constructor(options: CollectionOptions, context: CollectionContext);
|
|
80
80
|
get filterTargetKey(): string | string[];
|
|
81
|
-
isMultiFilterTargetKey(): boolean;
|
|
82
81
|
get name(): string;
|
|
83
82
|
get origin(): string;
|
|
84
83
|
get titleField(): string;
|
|
85
84
|
get db(): Database;
|
|
86
85
|
get treeParentField(): BelongsToField | null;
|
|
87
86
|
get treeChildrenField(): HasManyField | null;
|
|
87
|
+
isMultiFilterTargetKey(): boolean;
|
|
88
88
|
tableName(): any;
|
|
89
89
|
/**
|
|
90
90
|
* @internal
|
|
@@ -132,6 +132,8 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
132
132
|
tableNameAsString(options?: {
|
|
133
133
|
ignorePublicSchema: boolean;
|
|
134
134
|
}): any;
|
|
135
|
+
getRealTableName(quoted?: boolean): any;
|
|
136
|
+
getRealFieldName(name: string, quoted?: boolean): string;
|
|
135
137
|
getTableNameWithSchemaAsString(): string;
|
|
136
138
|
quotedTableName(): any;
|
|
137
139
|
collectionSchema(): string;
|
package/lib/collection.js
CHANGED
|
@@ -51,11 +51,11 @@ module.exports = __toCommonJS(collection_exports);
|
|
|
51
51
|
var import_deepmerge = __toESM(require("deepmerge"));
|
|
52
52
|
var import_events = require("events");
|
|
53
53
|
var import_lodash = __toESM(require("lodash"));
|
|
54
|
+
var import_safe_json_stringify = __toESM(require("safe-json-stringify"));
|
|
54
55
|
var import_sequelize = require("sequelize");
|
|
55
56
|
var import_model = require("./model");
|
|
56
57
|
var import_repository = require("./repository");
|
|
57
58
|
var import_utils = require("./utils");
|
|
58
|
-
var import_safe_json_stringify = __toESM(require("safe-json-stringify"));
|
|
59
59
|
function EnsureAtomicity(target, propertyKey, descriptor) {
|
|
60
60
|
const originalMethod = descriptor.value;
|
|
61
61
|
descriptor.value = function(...args) {
|
|
@@ -123,9 +123,6 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
123
123
|
}
|
|
124
124
|
return this.model.primaryKeyAttribute;
|
|
125
125
|
}
|
|
126
|
-
isMultiFilterTargetKey() {
|
|
127
|
-
return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1;
|
|
128
|
-
}
|
|
129
126
|
get name() {
|
|
130
127
|
return this.options.name;
|
|
131
128
|
}
|
|
@@ -152,6 +149,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
152
149
|
}
|
|
153
150
|
}
|
|
154
151
|
}
|
|
152
|
+
isMultiFilterTargetKey() {
|
|
153
|
+
return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1;
|
|
154
|
+
}
|
|
155
155
|
tableName() {
|
|
156
156
|
const { name, tableName } = this.options;
|
|
157
157
|
const tName = tableName || name;
|
|
@@ -220,6 +220,17 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
220
220
|
this._primaryKeyAttributes = value;
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
|
+
Object.defineProperty(this.model, "primaryKeyField", {
|
|
224
|
+
get: function() {
|
|
225
|
+
if (this.primaryKeyAttribute) {
|
|
226
|
+
return this.rawAttributes[this.primaryKeyAttribute].field || this.primaryKeyAttribute;
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}.bind(this.model),
|
|
230
|
+
set(val) {
|
|
231
|
+
this._primaryKeyField = val;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
223
234
|
this.model.init(null, this.sequelizeModelOptions());
|
|
224
235
|
this.model.options.modelName = this.options.name;
|
|
225
236
|
if (!autoGenId) {
|
|
@@ -471,6 +482,9 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
471
482
|
updateOptions(options, mergeOptions) {
|
|
472
483
|
let newOptions = import_lodash.default.cloneDeep(options);
|
|
473
484
|
newOptions = (0, import_deepmerge.default)(this.options, newOptions, mergeOptions);
|
|
485
|
+
if (options.filterTargetKey) {
|
|
486
|
+
newOptions.filterTargetKey = options.filterTargetKey;
|
|
487
|
+
}
|
|
474
488
|
this.context.database.emit("beforeUpdateCollection", this, newOptions);
|
|
475
489
|
this.options = newOptions;
|
|
476
490
|
this.setFields(options.fields, false);
|
|
@@ -636,6 +650,14 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
636
650
|
}
|
|
637
651
|
return `${schema}.${tableName}`;
|
|
638
652
|
}
|
|
653
|
+
getRealTableName(quoted = false) {
|
|
654
|
+
const realname = this.tableNameAsString();
|
|
655
|
+
return !quoted ? realname : this.db.sequelize.getQueryInterface().quoteIdentifiers(realname);
|
|
656
|
+
}
|
|
657
|
+
getRealFieldName(name, quoted = false) {
|
|
658
|
+
const realname = this.model.getAttributes()[name].field;
|
|
659
|
+
return !quoted ? name : this.db.sequelize.getQueryInterface().quoteIdentifier(realname);
|
|
660
|
+
}
|
|
639
661
|
getTableNameWithSchemaAsString() {
|
|
640
662
|
const tableName = this.model.tableName;
|
|
641
663
|
if (this.collectionSchema() && this.db.inDialect("postgres")) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.20241031134640",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "AGPL-3.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "1.4.0-alpha.
|
|
10
|
-
"@nocobase/utils": "1.4.0-alpha.
|
|
9
|
+
"@nocobase/logger": "1.4.0-alpha.20241031134640",
|
|
10
|
+
"@nocobase/utils": "1.4.0-alpha.20241031134640",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "78cd6d9010f81b1c4d13d7673f6adf2eb0e598be"
|
|
42
42
|
}
|