@nocobase/database 2.0.0-alpha.53 → 2.0.0-alpha.54

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.js CHANGED
@@ -295,6 +295,7 @@ const _Collection = class _Collection extends import_events.EventEmitter {
295
295
  this.model.options.modelName = this.options.name;
296
296
  if (!autoGenId) {
297
297
  this.model.removeAttribute("id");
298
+ this.model.autoIncrementAttribute = null;
298
299
  }
299
300
  this.model.database = this.context.database;
300
301
  this.model.collection = this;
package/lib/database.js CHANGED
@@ -438,7 +438,7 @@ const _Database = class _Database extends import_events.EventEmitter {
438
438
  this.emit("beforeDefineCollection", options);
439
439
  const collection = this.collectionFactory.createCollection(options);
440
440
  this.collections.set(collection.name, collection);
441
- this.emit("afterDefineCollection", collection);
441
+ this.emit("afterDefineCollection", collection, { fieldModels: options.fieldModels });
442
442
  return collection;
443
443
  }
444
444
  getTablePrefix() {
@@ -487,6 +487,9 @@ const _Database = class _Database extends import_events.EventEmitter {
487
487
  }
488
488
  removeCollection(name) {
489
489
  const collection = this.collections.get(name);
490
+ if (!collection) {
491
+ return;
492
+ }
490
493
  this.emit("beforeRemoveCollection", collection);
491
494
  collection.resetFields();
492
495
  const result = this.collections.delete(name);
@@ -78,7 +78,7 @@ const queryParentSQL = /* @__PURE__ */ __name((options) => {
78
78
  return `WITH RECURSIVE cte AS (
79
79
  SELECT ${q(targetKeyField)}, ${q(foreignKeyField)}
80
80
  FROM ${tableName}
81
- WHERE ${q(targetKeyField)} IN (${nodeIds.join(",")})
81
+ WHERE ${q(targetKeyField)} IN ('${nodeIds.join("','")}')
82
82
  UNION ALL
83
83
  SELECT t.${q(targetKeyField)}, t.${q(foreignKeyField)}
84
84
  FROM ${tableName} AS t
@@ -131,12 +131,16 @@ const _Field = class _Field {
131
131
  Object.assign(this.options, obj);
132
132
  }
133
133
  bind() {
134
+ var _a;
134
135
  const { model } = this.context.collection;
135
136
  model.rawAttributes[this.name] = this.toSequelize();
136
137
  model.refreshAttributes();
137
138
  if (this.options.index) {
138
139
  this.context.collection.addIndex([this.name]);
139
140
  }
141
+ if (((_a = this.options) == null ? void 0 : _a.autoIncrement) === true && !model.autoIncrementAttribute) {
142
+ model._findAutoIncrementAttribute();
143
+ }
140
144
  }
141
145
  unbind() {
142
146
  const { model } = this.context.collection;
@@ -49,9 +49,17 @@ const _SnowflakeIdField = class _SnowflakeIdField extends import_field.Field {
49
49
  }
50
50
  }
51
51
  init() {
52
- const { name } = this.options;
53
- this.listener = (instance) => this.setId(name, instance);
52
+ const { name, autoFill } = this.options;
53
+ this.listener = (instance) => {
54
+ if (autoFill === false) {
55
+ return;
56
+ }
57
+ this.setId(name, instance);
58
+ };
54
59
  this.bulkListener = async (instances) => {
60
+ if (autoFill === false) {
61
+ return;
62
+ }
55
63
  for (const instance of instances) {
56
64
  this.setId(name, instance);
57
65
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.0.0-alpha.53",
3
+ "version": "2.0.0-alpha.54",
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": "2.0.0-alpha.53",
10
- "@nocobase/utils": "2.0.0-alpha.53",
9
+ "@nocobase/logger": "2.0.0-alpha.54",
10
+ "@nocobase/utils": "2.0.0-alpha.54",
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": "ff30cf8261f5a97b3f24c3752af5bbc564167b37"
42
+ "gitHead": "68c84deaabba0ebec7407bf7245376b8d843449c"
43
43
  }