@nocobase/database 1.9.0-beta.15 → 1.9.0-beta.17

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.
@@ -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;
@@ -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) => this.model.rawAttributes[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) => this.model.rawAttributes[field].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 = { ...options.dialectOptions || {}, supportBigNumbers: true, bigNumberStrings: true };
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() {
@@ -162,6 +162,9 @@ const _SyncRunner = class _SyncRunner {
162
162
  }, "isJSONColumn");
163
163
  for (const columnName in columns) {
164
164
  const column = columns[columnName];
165
+ if (isJSONColumn(column) && this.database.inDialect("mysql")) {
166
+ continue;
167
+ }
165
168
  const isPrimaryKey = /* @__PURE__ */ __name(() => {
166
169
  const attribute = this.findAttributeByColumnName(columnName);
167
170
  return attribute && attribute.primaryKey || column.primaryKey;
@@ -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<any>;
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":
@@ -223,11 +220,11 @@ async function updateSingleAssociation(model, key, value, options = {}) {
223
220
  }
224
221
  }, "checkBelongsToForeignKeyValue");
225
222
  if ((0, import_utils.isStringOrNumber)(value)) {
226
- await model[setAccessor](value, { context, transaction });
223
+ await model[setAccessor](value, { context, transaction, associationKey: key });
227
224
  return true;
228
225
  }
229
226
  if (value instanceof import_model.Model) {
230
- await model[setAccessor](value, { context, transaction });
227
+ await model[setAccessor](value, { context, transaction, associationKey: key });
231
228
  model.setDataValue(key, value);
232
229
  return true;
233
230
  }
@@ -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, associationKey: key });
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, associationKey: key });
278
275
  await updateAssociations(instance, value, {
279
276
  ...options,
280
277
  transaction,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "1.9.0-beta.15",
3
+ "version": "1.9.0-beta.17",
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.15",
10
- "@nocobase/utils": "1.9.0-beta.15",
9
+ "@nocobase/logger": "1.9.0-beta.17",
10
+ "@nocobase/utils": "1.9.0-beta.17",
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": "f7285eff753fd268350cfd65cd079a35b8957f0e"
42
+ "gitHead": "4f95b676235fa3f7583493412279d8132a20c4d0"
43
43
  }