@nocobase/database 1.9.0-beta.16 → 1.9.0-beta.18
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/belongs-to-array/belongs-to-array-repository.d.ts +0 -2
- package/lib/belongs-to-array/belongs-to-array-repository.js +0 -13
- package/lib/collection.d.ts +1 -0
- package/lib/collection.js +19 -3
- package/lib/dialects/mariadb-dialect.js +6 -1
- package/lib/interfaces/time-interface.js +1 -1
- package/lib/relation-repository/single-relation-repository.js +1 -2
- package/lib/update-associations.d.ts +2 -4
- package/lib/update-associations.js +5 -8
- package/package.json +4 -4
|
@@ -12,7 +12,6 @@ import { FindOptions } from '../repository';
|
|
|
12
12
|
import { MultipleRelationRepository } from '../relation-repository/multiple-relation-repository';
|
|
13
13
|
import Database from '../database';
|
|
14
14
|
import { Model } from '../model';
|
|
15
|
-
import { UpdateAssociationOptions } from '../update-associations';
|
|
16
15
|
export declare class BelongsToArrayAssociation {
|
|
17
16
|
db: Database;
|
|
18
17
|
associationType: string;
|
|
@@ -35,7 +34,6 @@ export declare class BelongsToArrayAssociation {
|
|
|
35
34
|
generateInclude(parentAs?: string): {
|
|
36
35
|
on: void;
|
|
37
36
|
};
|
|
38
|
-
update(instance: Model, value: any, options?: UpdateAssociationOptions): Promise<void>;
|
|
39
37
|
}
|
|
40
38
|
export declare class BelongsToArrayRepository extends MultipleRelationRepository {
|
|
41
39
|
private belongsToArrayAssociation;
|
|
@@ -94,19 +94,6 @@ const _BelongsToArrayAssociation = class _BelongsToArrayAssociation {
|
|
|
94
94
|
on: this.db.queryInterface.generateJoinOnForJSONArray(left, right)
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
async update(instance, value, options = {}) {
|
|
98
|
-
await instance.update(
|
|
99
|
-
{
|
|
100
|
-
[this.as]: value
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
values: {
|
|
104
|
-
[this.as]: value
|
|
105
|
-
},
|
|
106
|
-
transaction: options == null ? void 0 : options.transaction
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
97
|
};
|
|
111
98
|
__name(_BelongsToArrayAssociation, "BelongsToArrayAssociation");
|
|
112
99
|
let BelongsToArrayAssociation = _BelongsToArrayAssociation;
|
package/lib/collection.d.ts
CHANGED
|
@@ -124,6 +124,7 @@ export declare class Collection<TModelAttributes extends {} = any, TCreationAttr
|
|
|
124
124
|
updateOptions(options: CollectionOptions, mergeOptions?: any): this;
|
|
125
125
|
setSortable(sortable: any): void;
|
|
126
126
|
updateField(name: string, options: FieldOptions): void;
|
|
127
|
+
private normalizeFieldName;
|
|
127
128
|
addIndex(index: string | string[] | {
|
|
128
129
|
fields: string[];
|
|
129
130
|
unique?: boolean;
|
package/lib/collection.js
CHANGED
|
@@ -591,6 +591,12 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
591
591
|
}
|
|
592
592
|
this.setField(options.name || name, options);
|
|
593
593
|
}
|
|
594
|
+
normalizeFieldName(val) {
|
|
595
|
+
if (!this.options.underscored) {
|
|
596
|
+
return val;
|
|
597
|
+
}
|
|
598
|
+
return Array.isArray(val) ? val.map((v) => (0, import_utils.snakeCase)(v)) : (0, import_utils.snakeCase)(val);
|
|
599
|
+
}
|
|
594
600
|
addIndex(index) {
|
|
595
601
|
if (!index) {
|
|
596
602
|
return;
|
|
@@ -620,7 +626,7 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
620
626
|
return;
|
|
621
627
|
}
|
|
622
628
|
for (const item of indexes) {
|
|
623
|
-
if (import_lodash.default.isEqual(item.fields, indexName)) {
|
|
629
|
+
if (import_lodash.default.isEqual(this.normalizeFieldName(item.fields), this.normalizeFieldName(indexName))) {
|
|
624
630
|
return;
|
|
625
631
|
}
|
|
626
632
|
const name2 = item.fields.join(",");
|
|
@@ -656,11 +662,21 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
656
662
|
*/
|
|
657
663
|
refreshIndexes() {
|
|
658
664
|
const indexes = this.model._indexes;
|
|
665
|
+
const attributes = {};
|
|
666
|
+
for (const [name, field] of Object.entries(this.model.getAttributes())) {
|
|
667
|
+
attributes[this.normalizeFieldName(name)] = field;
|
|
668
|
+
}
|
|
659
669
|
this.model._indexes = import_lodash.default.uniqBy(
|
|
660
670
|
indexes.filter((item) => {
|
|
661
|
-
return item.fields.every((field) =>
|
|
671
|
+
return item.fields.every((field) => {
|
|
672
|
+
const name = this.normalizeFieldName(field);
|
|
673
|
+
return attributes[name];
|
|
674
|
+
});
|
|
662
675
|
}).map((item) => {
|
|
663
|
-
item.fields = item.fields.map((field) =>
|
|
676
|
+
item.fields = item.fields.map((field) => {
|
|
677
|
+
const name = this.normalizeFieldName(field);
|
|
678
|
+
return attributes[name].field;
|
|
679
|
+
});
|
|
664
680
|
return item;
|
|
665
681
|
}),
|
|
666
682
|
"name"
|
|
@@ -35,7 +35,12 @@ module.exports = __toCommonJS(mariadb_dialect_exports);
|
|
|
35
35
|
var import_base_dialect = require("./base-dialect");
|
|
36
36
|
const _MariadbDialect = class _MariadbDialect extends import_base_dialect.BaseDialect {
|
|
37
37
|
getSequelizeOptions(options) {
|
|
38
|
-
options.dialectOptions = {
|
|
38
|
+
options.dialectOptions = {
|
|
39
|
+
...options.dialectOptions || {},
|
|
40
|
+
multipleStatements: true,
|
|
41
|
+
supportBigNumbers: true,
|
|
42
|
+
bigNumberStrings: true
|
|
43
|
+
};
|
|
39
44
|
return options;
|
|
40
45
|
}
|
|
41
46
|
getVersionGuard() {
|
|
@@ -47,7 +47,7 @@ import_dayjs.default.extend(import_utc.default);
|
|
|
47
47
|
const _TimeInterface = class _TimeInterface extends import_base_interface.BaseInterface {
|
|
48
48
|
toValue(value, ctx) {
|
|
49
49
|
if (this.validate(value)) {
|
|
50
|
-
const result = import_dayjs.default
|
|
50
|
+
const result = (0, import_dayjs.default)(value).format("HH:mm:ss");
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
53
53
|
return value;
|
|
@@ -51,7 +51,6 @@ module.exports = __toCommonJS(single_relation_repository_exports);
|
|
|
51
51
|
var import_target_collection_decorator = __toESM(require("../decorators/target-collection-decorator"));
|
|
52
52
|
var import_update_associations = require("../update-associations");
|
|
53
53
|
var import_relation_repository = require("./relation-repository");
|
|
54
|
-
var import_lodash = __toESM(require("lodash"));
|
|
55
54
|
const _SingleRelationRepository = class _SingleRelationRepository extends import_relation_repository.RelationRepository {
|
|
56
55
|
async remove(options) {
|
|
57
56
|
const transaction2 = await this.getTransaction(options);
|
|
@@ -104,7 +103,7 @@ const _SingleRelationRepository = class _SingleRelationRepository extends import
|
|
|
104
103
|
throw new Error("The record does not exist");
|
|
105
104
|
}
|
|
106
105
|
await (0, import_update_associations.updateModelByValues)(target, options == null ? void 0 : options.values, {
|
|
107
|
-
...
|
|
106
|
+
...options,
|
|
108
107
|
transaction: transaction2
|
|
109
108
|
});
|
|
110
109
|
if (options.hooks !== false) {
|
|
@@ -13,9 +13,7 @@ export declare function modelAssociations(instance: Model): {
|
|
|
13
13
|
[key: string]: Association<import("sequelize").Model<any, any>, import("sequelize").Model<any, any>>;
|
|
14
14
|
};
|
|
15
15
|
export declare function belongsToManyAssociations(instance: Model): Array<BelongsToMany>;
|
|
16
|
-
export declare function modelAssociationByKey(instance: Model, key: string): Association
|
|
17
|
-
update?: (instance: Model, value: any, options: UpdateAssociationOptions) => Promise<any>;
|
|
18
|
-
};
|
|
16
|
+
export declare function modelAssociationByKey(instance: Model, key: string): Association;
|
|
19
17
|
type UpdateValue = {
|
|
20
18
|
[key: string]: any;
|
|
21
19
|
};
|
|
@@ -51,7 +49,7 @@ export declare function updateAssociations(instance: Model, values: any, options
|
|
|
51
49
|
* @param value
|
|
52
50
|
* @param options
|
|
53
51
|
*/
|
|
54
|
-
export declare function updateAssociation(instance: Model, key: string, value: any, options?: UpdateAssociationOptions): Promise<
|
|
52
|
+
export declare function updateAssociation(instance: Model, key: string, value: any, options?: UpdateAssociationOptions): Promise<boolean>;
|
|
55
53
|
/**
|
|
56
54
|
* update belongsTo and HasOne
|
|
57
55
|
* @param model
|
|
@@ -176,9 +176,6 @@ async function updateAssociation(instance, key, value, options = {}) {
|
|
|
176
176
|
if (options.associationContext && isReverseAssociationPair(association, options.associationContext)) {
|
|
177
177
|
return false;
|
|
178
178
|
}
|
|
179
|
-
if (association.update) {
|
|
180
|
-
return association.update(instance, value, options);
|
|
181
|
-
}
|
|
182
179
|
switch (association.associationType) {
|
|
183
180
|
case "HasOne":
|
|
184
181
|
case "BelongsTo":
|
|
@@ -258,7 +255,7 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
258
255
|
if (association.associationType === "HasOne") {
|
|
259
256
|
delete updateValues[association.foreignKey];
|
|
260
257
|
}
|
|
261
|
-
await instance2.update(updateValues, { ...options, transaction });
|
|
258
|
+
await instance2.update(updateValues, { ...options, transaction, inputValues: updateValues });
|
|
262
259
|
}
|
|
263
260
|
await updateAssociations(instance2, value, {
|
|
264
261
|
...options,
|
|
@@ -274,7 +271,7 @@ async function updateSingleAssociation(model, key, value, options = {}) {
|
|
|
274
271
|
values: value,
|
|
275
272
|
operation: "create"
|
|
276
273
|
});
|
|
277
|
-
const instance = await model[createAccessor](value, { context, transaction });
|
|
274
|
+
const instance = await model[createAccessor](value, { context, transaction, inputValues: value });
|
|
278
275
|
await updateAssociations(instance, value, {
|
|
279
276
|
...options,
|
|
280
277
|
transaction,
|
|
@@ -368,7 +365,7 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
368
365
|
values: item,
|
|
369
366
|
operation: "create"
|
|
370
367
|
});
|
|
371
|
-
const instance = await model[createAccessor](item, accessorOptions);
|
|
368
|
+
const instance = await model[createAccessor](item, { ...accessorOptions, inputValues: item });
|
|
372
369
|
await updateAssociations(instance, item, {
|
|
373
370
|
...options,
|
|
374
371
|
transaction,
|
|
@@ -389,7 +386,7 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
389
386
|
values: item,
|
|
390
387
|
operation: "create"
|
|
391
388
|
});
|
|
392
|
-
instance = await model[createAccessor](item, accessorOptions);
|
|
389
|
+
instance = await model[createAccessor](item, { ...accessorOptions, inputValues: item });
|
|
393
390
|
await updateAssociations(instance, item, {
|
|
394
391
|
...options,
|
|
395
392
|
transaction,
|
|
@@ -412,7 +409,7 @@ async function updateMultipleAssociation(model, key, value, options = {}) {
|
|
|
412
409
|
values: item,
|
|
413
410
|
operation: "update"
|
|
414
411
|
});
|
|
415
|
-
await instance.update(item, { ...options, transaction });
|
|
412
|
+
await instance.update(item, { ...options, transaction, inputValues: item });
|
|
416
413
|
}
|
|
417
414
|
await updateAssociations(instance, item, {
|
|
418
415
|
...options,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.18",
|
|
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.9.0-beta.
|
|
10
|
-
"@nocobase/utils": "1.9.0-beta.
|
|
9
|
+
"@nocobase/logger": "1.9.0-beta.18",
|
|
10
|
+
"@nocobase/utils": "1.9.0-beta.18",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
40
40
|
"directory": "packages/database"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1c211ab8c30d9442c38d07e2ebef2c2935e0fbac"
|
|
43
43
|
}
|