@nocobase/database 1.3.0-alpha.20240819011229 → 1.4.0-alpha.20240825165425
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 +1 -0
- package/lib/collection.js +0 -4
- package/lib/database.js +5 -2
- package/lib/eager-loading/eager-loading-tree.js +20 -2
- package/lib/fields/date-field.d.ts +2 -4
- package/lib/fields/date-field.js +0 -51
- package/lib/fields/field.d.ts +1 -1
- package/lib/fields/field.js +2 -3
- package/lib/fields/index.d.ts +1 -5
- package/lib/fields/index.js +1 -5
- package/lib/fields/string-field.d.ts +2 -1
- package/lib/fields/string-field.js +3 -0
- package/lib/model.d.ts +0 -1
- package/lib/model.js +0 -12
- package/lib/relation-repository/multiple-relation-repository.d.ts +2 -1
- package/lib/repository.d.ts +1 -1
- package/lib/repository.js +2 -2
- package/lib/view/field-type-map.js +7 -7
- package/package.json +4 -4
- package/lib/fields/date-only-field.d.ts +0 -15
- package/lib/fields/date-only-field.js +0 -45
- package/lib/fields/unix-timestamp-field.d.ts +0 -18
- package/lib/fields/unix-timestamp-field.js +0 -76
- package/lib/repositories/tree-repository/adjacency-list-repository.d.ts +0 -26
- package/lib/repositories/tree-repository/adjacency-list-repository.js +0 -192
package/lib/collection.d.ts
CHANGED
package/lib/collection.js
CHANGED
|
@@ -53,7 +53,6 @@ var import_events = require("events");
|
|
|
53
53
|
var import_lodash = __toESM(require("lodash"));
|
|
54
54
|
var import_sequelize = require("sequelize");
|
|
55
55
|
var import_model = require("./model");
|
|
56
|
-
var import_adjacency_list_repository = require("./repositories/tree-repository/adjacency-list-repository");
|
|
57
56
|
var import_repository = require("./repository");
|
|
58
57
|
var import_utils = require("./utils");
|
|
59
58
|
var import_safe_json_stringify = __toESM(require("safe-json-stringify"));
|
|
@@ -189,9 +188,6 @@ const _Collection = class _Collection extends import_events.EventEmitter {
|
|
|
189
188
|
if (typeof repository === "string") {
|
|
190
189
|
repo = this.context.database.repositories.get(repository) || import_repository.Repository;
|
|
191
190
|
}
|
|
192
|
-
if (this.options.tree == "adjacency-list" || this.options.tree == "adjacencyList") {
|
|
193
|
-
repo = import_adjacency_list_repository.AdjacencyListRepository;
|
|
194
|
-
}
|
|
195
191
|
this.repository = new repo(this);
|
|
196
192
|
}
|
|
197
193
|
forEachField(callback) {
|
package/lib/database.js
CHANGED
|
@@ -64,6 +64,7 @@ var import_database_utils = __toESM(require("./database-utils"));
|
|
|
64
64
|
var import_references_map = __toESM(require("./features/references-map"));
|
|
65
65
|
var import_referential_integrity_check = require("./features/referential-integrity-check");
|
|
66
66
|
var FieldTypes = __toESM(require("./fields"));
|
|
67
|
+
var import_helpers = require("./helpers");
|
|
67
68
|
var import_inherited_collection = require("./inherited-collection");
|
|
68
69
|
var import_inherited_map = __toESM(require("./inherited-map"));
|
|
69
70
|
var import_interface_manager = require("./interface-manager");
|
|
@@ -158,7 +159,6 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
158
159
|
opts.storage = (0, import_path.resolve)(process.cwd(), options.storage);
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
|
-
opts.rawTimezone = opts.timezone;
|
|
162
162
|
if (options.dialect === "sqlite") {
|
|
163
163
|
delete opts.timezone;
|
|
164
164
|
} else if (!opts.timezone) {
|
|
@@ -367,6 +367,9 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
367
367
|
options.indexes = options.indexes.map((index) => {
|
|
368
368
|
if (index.fields) {
|
|
369
369
|
index.fields = index.fields.map((field) => {
|
|
370
|
+
if (field.name) {
|
|
371
|
+
return { name: (0, import_utils3.snakeCase)(field.name), ...field };
|
|
372
|
+
}
|
|
370
373
|
return (0, import_utils3.snakeCase)(field);
|
|
371
374
|
});
|
|
372
375
|
}
|
|
@@ -658,7 +661,7 @@ const _Database = class _Database extends import_events.EventEmitter {
|
|
|
658
661
|
* @internal
|
|
659
662
|
*/
|
|
660
663
|
async checkVersion() {
|
|
661
|
-
return
|
|
664
|
+
return await (0, import_helpers.checkDatabaseVersion)(this);
|
|
662
665
|
}
|
|
663
666
|
/**
|
|
664
667
|
* @internal
|
|
@@ -44,7 +44,6 @@ var import_lodash = __toESM(require("lodash"));
|
|
|
44
44
|
var import_sequelize = require("sequelize");
|
|
45
45
|
var import_append_child_collection_name_after_repository_find = require("../listeners/append-child-collection-name-after-repository-find");
|
|
46
46
|
var import_options_parser = require("../options-parser");
|
|
47
|
-
var import_adjacency_list_repository = require("../repositories/tree-repository/adjacency-list-repository");
|
|
48
47
|
const pushAttribute = /* @__PURE__ */ __name((node, attribute) => {
|
|
49
48
|
if (import_lodash.default.isArray(node.attributes) && !node.attributes.includes(attribute)) {
|
|
50
49
|
node.attributes.push(attribute);
|
|
@@ -67,6 +66,25 @@ const EagerLoadingNodeProto = {
|
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
};
|
|
69
|
+
const queryParentSQL = /* @__PURE__ */ __name((options) => {
|
|
70
|
+
const { collection, db, nodeIds } = options;
|
|
71
|
+
const tableName = collection.quotedTableName();
|
|
72
|
+
const { foreignKey, targetKey } = options;
|
|
73
|
+
const foreignKeyField = collection.model.rawAttributes[foreignKey].field;
|
|
74
|
+
const targetKeyField = collection.model.rawAttributes[targetKey].field;
|
|
75
|
+
const queryInterface = db.sequelize.getQueryInterface();
|
|
76
|
+
const q = queryInterface.quoteIdentifier.bind(queryInterface);
|
|
77
|
+
return `WITH RECURSIVE cte AS (
|
|
78
|
+
SELECT ${q(targetKeyField)}, ${q(foreignKeyField)}
|
|
79
|
+
FROM ${tableName}
|
|
80
|
+
WHERE ${q(targetKeyField)} IN (${nodeIds.join(",")})
|
|
81
|
+
UNION ALL
|
|
82
|
+
SELECT t.${q(targetKeyField)}, t.${q(foreignKeyField)}
|
|
83
|
+
FROM ${tableName} AS t
|
|
84
|
+
INNER JOIN cte ON t.${q(targetKeyField)} = cte.${q(foreignKeyField)}
|
|
85
|
+
)
|
|
86
|
+
SELECT ${q(targetKeyField)} AS ${q(targetKey)}, ${q(foreignKeyField)} AS ${q(foreignKey)} FROM cte`;
|
|
87
|
+
}, "queryParentSQL");
|
|
70
88
|
const _EagerLoadingTree = class _EagerLoadingTree {
|
|
71
89
|
root;
|
|
72
90
|
db;
|
|
@@ -289,7 +307,7 @@ const _EagerLoadingTree = class _EagerLoadingTree {
|
|
|
289
307
|
});
|
|
290
308
|
if (node.includeOption.recursively && instances.length > 0) {
|
|
291
309
|
const targetKey = association.targetKey;
|
|
292
|
-
const sql =
|
|
310
|
+
const sql = queryParentSQL({
|
|
293
311
|
db: this.db,
|
|
294
312
|
collection: collection2,
|
|
295
313
|
foreignKey,
|
|
@@ -6,17 +6,15 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
import { DataTypes } from 'sequelize';
|
|
9
10
|
import { BaseColumnFieldOptions, Field } from './field';
|
|
10
11
|
export declare class DateField extends Field {
|
|
11
|
-
get dataType():
|
|
12
|
+
get dataType(): DataTypes.DateDataType;
|
|
12
13
|
get timezone(): string;
|
|
13
14
|
getProps(): any;
|
|
14
15
|
isDateOnly(): boolean;
|
|
15
16
|
isGMT(): any;
|
|
16
|
-
init(): void;
|
|
17
|
-
setter(value: any, options: any): any;
|
|
18
17
|
bind(): void;
|
|
19
|
-
unbind(): void;
|
|
20
18
|
}
|
|
21
19
|
export interface DateFieldOptions extends BaseColumnFieldOptions {
|
|
22
20
|
type: 'date';
|
package/lib/fields/date-field.js
CHANGED
|
@@ -32,11 +32,6 @@ __export(date_field_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(date_field_exports);
|
|
33
33
|
var import_sequelize = require("sequelize");
|
|
34
34
|
var import_field = require("./field");
|
|
35
|
-
const datetimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
|
36
|
-
function isValidDatetime(str) {
|
|
37
|
-
return datetimeRegex.test(str);
|
|
38
|
-
}
|
|
39
|
-
__name(isValidDatetime, "isValidDatetime");
|
|
40
35
|
const _DateField = class _DateField extends import_field.Field {
|
|
41
36
|
get dataType() {
|
|
42
37
|
return import_sequelize.DataTypes.DATE(3);
|
|
@@ -56,47 +51,6 @@ const _DateField = class _DateField extends import_field.Field {
|
|
|
56
51
|
const props = this.getProps();
|
|
57
52
|
return props.gmt;
|
|
58
53
|
}
|
|
59
|
-
init() {
|
|
60
|
-
const { name, defaultToCurrentTime, onUpdateToCurrentTime, timezone } = this.options;
|
|
61
|
-
this.resolveTimeZone = (context) => {
|
|
62
|
-
const serverTimeZone = this.database.options.rawTimezone;
|
|
63
|
-
if (timezone === "server") {
|
|
64
|
-
return serverTimeZone;
|
|
65
|
-
}
|
|
66
|
-
if (timezone === "client") {
|
|
67
|
-
return (context == null ? void 0 : context.timezone) || serverTimeZone;
|
|
68
|
-
}
|
|
69
|
-
if (timezone) {
|
|
70
|
-
return timezone;
|
|
71
|
-
}
|
|
72
|
-
return serverTimeZone;
|
|
73
|
-
};
|
|
74
|
-
this.beforeSave = async (instance, options) => {
|
|
75
|
-
const value = instance.get(name);
|
|
76
|
-
if (!value && instance.isNewRecord && defaultToCurrentTime) {
|
|
77
|
-
instance.set(name, /* @__PURE__ */ new Date());
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (onUpdateToCurrentTime) {
|
|
81
|
-
instance.set(name, /* @__PURE__ */ new Date());
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
setter(value, options) {
|
|
87
|
-
if (value === null) {
|
|
88
|
-
return value;
|
|
89
|
-
}
|
|
90
|
-
if (value instanceof Date) {
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
if (typeof value === "string" && isValidDatetime(value)) {
|
|
94
|
-
const dateTimezone = this.resolveTimeZone(options == null ? void 0 : options.context);
|
|
95
|
-
const dateString = `${value} ${dateTimezone}`;
|
|
96
|
-
return new Date(dateString);
|
|
97
|
-
}
|
|
98
|
-
return value;
|
|
99
|
-
}
|
|
100
54
|
bind() {
|
|
101
55
|
super.bind();
|
|
102
56
|
if (this.options.interface === "createdAt") {
|
|
@@ -109,11 +63,6 @@ const _DateField = class _DateField extends import_field.Field {
|
|
|
109
63
|
model._timestampAttributes.updatedAt = this.name;
|
|
110
64
|
model.refreshAttributes();
|
|
111
65
|
}
|
|
112
|
-
this.on("beforeSave", this.beforeSave);
|
|
113
|
-
}
|
|
114
|
-
unbind() {
|
|
115
|
-
super.unbind();
|
|
116
|
-
this.off("beforeSave", this.beforeSave);
|
|
117
66
|
}
|
|
118
67
|
};
|
|
119
68
|
__name(_DateField, "DateField");
|
package/lib/fields/field.d.ts
CHANGED
package/lib/fields/field.js
CHANGED
|
@@ -151,11 +151,10 @@ const _Field = class _Field {
|
|
|
151
151
|
if (this.dataType) {
|
|
152
152
|
Object.assign(opts, { type: this.database.sequelize.normalizeDataType(this.dataType) });
|
|
153
153
|
}
|
|
154
|
-
Object.assign(opts, this.additionalSequelizeOptions());
|
|
155
154
|
return opts;
|
|
156
155
|
}
|
|
157
|
-
|
|
158
|
-
return
|
|
156
|
+
isSqlite() {
|
|
157
|
+
return this.database.sequelize.getDialect() === "sqlite";
|
|
159
158
|
}
|
|
160
159
|
typeToString() {
|
|
161
160
|
return this.dataType.toString();
|
package/lib/fields/index.d.ts
CHANGED
|
@@ -29,15 +29,12 @@ import { UUIDFieldOptions } from './uuid-field';
|
|
|
29
29
|
import { VirtualFieldOptions } from './virtual-field';
|
|
30
30
|
import { NanoidFieldOptions } from './nanoid-field';
|
|
31
31
|
import { EncryptionField } from './encryption-field';
|
|
32
|
-
import { UnixTimestampFieldOptions } from './unix-timestamp-field';
|
|
33
|
-
import { DateOnlyFieldOptions } from './date-only-field';
|
|
34
32
|
export * from './array-field';
|
|
35
33
|
export * from './belongs-to-field';
|
|
36
34
|
export * from './belongs-to-many-field';
|
|
37
35
|
export * from './boolean-field';
|
|
38
36
|
export * from './context-field';
|
|
39
37
|
export * from './date-field';
|
|
40
|
-
export * from './date-only-field';
|
|
41
38
|
export * from './field';
|
|
42
39
|
export * from './has-many-field';
|
|
43
40
|
export * from './has-one-field';
|
|
@@ -56,5 +53,4 @@ export * from './uuid-field';
|
|
|
56
53
|
export * from './virtual-field';
|
|
57
54
|
export * from './nanoid-field';
|
|
58
55
|
export * from './encryption-field';
|
|
59
|
-
export
|
|
60
|
-
export type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | DateOnlyFieldOptions | UnixTimestampFieldOptions | UidFieldOptions | UUIDFieldOptions | NanoidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions | EncryptionField;
|
|
56
|
+
export type FieldOptions = BaseFieldOptions | StringFieldOptions | IntegerFieldOptions | FloatFieldOptions | DecimalFieldOptions | DoubleFieldOptions | RealFieldOptions | JsonFieldOptions | JsonbFieldOptions | BooleanFieldOptions | RadioFieldOptions | SortFieldOptions | TextFieldOptions | VirtualFieldOptions | ArrayFieldOptions | SetFieldOptions | TimeFieldOptions | DateFieldOptions | UidFieldOptions | UUIDFieldOptions | NanoidFieldOptions | PasswordFieldOptions | ContextFieldOptions | BelongsToFieldOptions | HasOneFieldOptions | HasManyFieldOptions | BelongsToManyFieldOptions | EncryptionField;
|
package/lib/fields/index.js
CHANGED
|
@@ -29,7 +29,6 @@ __reExport(fields_exports, require("./belongs-to-many-field"), module.exports);
|
|
|
29
29
|
__reExport(fields_exports, require("./boolean-field"), module.exports);
|
|
30
30
|
__reExport(fields_exports, require("./context-field"), module.exports);
|
|
31
31
|
__reExport(fields_exports, require("./date-field"), module.exports);
|
|
32
|
-
__reExport(fields_exports, require("./date-only-field"), module.exports);
|
|
33
32
|
__reExport(fields_exports, require("./field"), module.exports);
|
|
34
33
|
__reExport(fields_exports, require("./has-many-field"), module.exports);
|
|
35
34
|
__reExport(fields_exports, require("./has-one-field"), module.exports);
|
|
@@ -48,7 +47,6 @@ __reExport(fields_exports, require("./uuid-field"), module.exports);
|
|
|
48
47
|
__reExport(fields_exports, require("./virtual-field"), module.exports);
|
|
49
48
|
__reExport(fields_exports, require("./nanoid-field"), module.exports);
|
|
50
49
|
__reExport(fields_exports, require("./encryption-field"), module.exports);
|
|
51
|
-
__reExport(fields_exports, require("./unix-timestamp-field"), module.exports);
|
|
52
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
51
|
0 && (module.exports = {
|
|
54
52
|
...require("./array-field"),
|
|
@@ -57,7 +55,6 @@ __reExport(fields_exports, require("./unix-timestamp-field"), module.exports);
|
|
|
57
55
|
...require("./boolean-field"),
|
|
58
56
|
...require("./context-field"),
|
|
59
57
|
...require("./date-field"),
|
|
60
|
-
...require("./date-only-field"),
|
|
61
58
|
...require("./field"),
|
|
62
59
|
...require("./has-many-field"),
|
|
63
60
|
...require("./has-one-field"),
|
|
@@ -75,6 +72,5 @@ __reExport(fields_exports, require("./unix-timestamp-field"), module.exports);
|
|
|
75
72
|
...require("./uuid-field"),
|
|
76
73
|
...require("./virtual-field"),
|
|
77
74
|
...require("./nanoid-field"),
|
|
78
|
-
...require("./encryption-field")
|
|
79
|
-
...require("./unix-timestamp-field")
|
|
75
|
+
...require("./encryption-field")
|
|
80
76
|
});
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
import { DataTypes } from 'sequelize';
|
|
10
10
|
import { BaseColumnFieldOptions, Field } from './field';
|
|
11
11
|
export declare class StringField extends Field {
|
|
12
|
-
get dataType(): DataTypes.StringDataTypeConstructor;
|
|
12
|
+
get dataType(): DataTypes.StringDataTypeConstructor | DataTypes.StringDataType;
|
|
13
13
|
}
|
|
14
14
|
export interface StringFieldOptions extends BaseColumnFieldOptions {
|
|
15
15
|
type: 'string';
|
|
16
|
+
length?: number;
|
|
16
17
|
}
|
|
@@ -34,6 +34,9 @@ var import_sequelize = require("sequelize");
|
|
|
34
34
|
var import_field = require("./field");
|
|
35
35
|
const _StringField = class _StringField extends import_field.Field {
|
|
36
36
|
get dataType() {
|
|
37
|
+
if (this.options.length) {
|
|
38
|
+
return import_sequelize.DataTypes.STRING(this.options.length);
|
|
39
|
+
}
|
|
37
40
|
return import_sequelize.DataTypes.STRING;
|
|
38
41
|
}
|
|
39
42
|
};
|
package/lib/model.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export declare class Model<TModelAttributes extends {} = any, TCreationAttribute
|
|
|
20
20
|
protected _previousDataValuesWithAssociations: {};
|
|
21
21
|
get db(): Database;
|
|
22
22
|
static sync(options: any): Promise<any>;
|
|
23
|
-
static callSetters(values: any, options: any): {};
|
|
24
23
|
toChangedWithAssociations(): void;
|
|
25
24
|
changedWithAssociations(key?: string, value?: any): boolean | unknown[] | this;
|
|
26
25
|
clearChangedWithAssociations(): void;
|
package/lib/model.js
CHANGED
|
@@ -56,18 +56,6 @@ const _Model = class _Model extends import_sequelize.Model {
|
|
|
56
56
|
const runner = new import_sync_runner.SyncRunner(this);
|
|
57
57
|
return await runner.runSync(options);
|
|
58
58
|
}
|
|
59
|
-
static callSetters(values, options) {
|
|
60
|
-
const result = {};
|
|
61
|
-
for (const key of Object.keys(values)) {
|
|
62
|
-
const field = this.collection.getField(key);
|
|
63
|
-
if (field && field.setter) {
|
|
64
|
-
result[key] = field.setter.call(field, values[key], options, values, key);
|
|
65
|
-
} else {
|
|
66
|
-
result[key] = values[key];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
59
|
// TODO
|
|
72
60
|
toChangedWithAssociations() {
|
|
73
61
|
this._changedWithAssociations = /* @__PURE__ */ new Set([...this._changedWithAssociations, ...this._changed]);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { MultiAssociationAccessors, Transaction, Transactionable } from 'sequelize';
|
|
10
10
|
import { CommonFindOptions, CountOptions, DestroyOptions, Filter, FindOneOptions, FindOptions, TargetKey, TK, UpdateOptions } from '../repository';
|
|
11
11
|
import { RelationRepository } from './relation-repository';
|
|
12
|
-
|
|
12
|
+
type FindAndCountOptions = CommonFindOptions;
|
|
13
13
|
export interface AssociatedOptions extends Transactionable {
|
|
14
14
|
tk?: TK;
|
|
15
15
|
}
|
|
@@ -25,3 +25,4 @@ export declare abstract class MultipleRelationRepository extends RelationReposit
|
|
|
25
25
|
protected filterHasInclude(filter: Filter, options?: any): boolean;
|
|
26
26
|
protected accessors(): MultiAssociationAccessors;
|
|
27
27
|
}
|
|
28
|
+
export {};
|
package/lib/repository.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export interface DestroyOptions extends SequelizeDestroyOptions {
|
|
|
80
80
|
truncate?: boolean;
|
|
81
81
|
context?: any;
|
|
82
82
|
}
|
|
83
|
-
type FindAndCountOptions = Omit<SequelizeAndCountOptions, 'where' | 'include' | 'order'> & CommonFindOptions;
|
|
83
|
+
export type FindAndCountOptions = Omit<SequelizeAndCountOptions, 'where' | 'include' | 'order'> & CommonFindOptions;
|
|
84
84
|
export interface CreateOptions extends SequelizeCreateOptions {
|
|
85
85
|
values?: Values | Values[];
|
|
86
86
|
whitelist?: WhiteList;
|
package/lib/repository.js
CHANGED
|
@@ -374,7 +374,7 @@ const _Repository = class _Repository {
|
|
|
374
374
|
action: "create",
|
|
375
375
|
underscored: this.collection.options.underscored
|
|
376
376
|
});
|
|
377
|
-
const values =
|
|
377
|
+
const values = guard.sanitize(options.values || {});
|
|
378
378
|
const instance = await this.model.create(values, {
|
|
379
379
|
...options,
|
|
380
380
|
transaction: transaction2
|
|
@@ -418,7 +418,7 @@ const _Repository = class _Repository {
|
|
|
418
418
|
}
|
|
419
419
|
const transaction2 = await this.getTransaction(options);
|
|
420
420
|
const guard = import_update_guard.UpdateGuard.fromOptions(this.model, { ...options, underscored: this.collection.options.underscored });
|
|
421
|
-
const values =
|
|
421
|
+
const values = guard.sanitize(options.values);
|
|
422
422
|
if (options.individualHooks === false) {
|
|
423
423
|
const { model: Model2 } = this.collection;
|
|
424
424
|
const primaryKeyField = Model2.primaryKeyField || Model2.primaryKeyAttribute;
|
|
@@ -38,8 +38,8 @@ const postgres = {
|
|
|
38
38
|
oid: "string",
|
|
39
39
|
name: "string",
|
|
40
40
|
smallint: ["integer", "sort"],
|
|
41
|
-
integer: ["integer", "
|
|
42
|
-
bigint: ["bigInt", "
|
|
41
|
+
integer: ["integer", "sort"],
|
|
42
|
+
bigint: ["bigInt", "sort"],
|
|
43
43
|
decimal: "decimal",
|
|
44
44
|
numeric: "float",
|
|
45
45
|
real: "float",
|
|
@@ -74,11 +74,11 @@ const mysql = {
|
|
|
74
74
|
text: "text",
|
|
75
75
|
mediumtext: "text",
|
|
76
76
|
longtext: "text",
|
|
77
|
-
int: ["integer", "
|
|
78
|
-
"int unsigned": ["integer", "
|
|
79
|
-
integer: ["integer", "
|
|
80
|
-
bigint: ["bigInt", "
|
|
81
|
-
"bigint unsigned": ["bigInt", "
|
|
77
|
+
int: ["integer", "sort"],
|
|
78
|
+
"int unsigned": ["integer", "sort"],
|
|
79
|
+
integer: ["integer", "sort"],
|
|
80
|
+
bigint: ["bigInt", "sort"],
|
|
81
|
+
"bigint unsigned": ["bigInt", "sort"],
|
|
82
82
|
float: "float",
|
|
83
83
|
double: "float",
|
|
84
84
|
boolean: "boolean",
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-alpha.20240825165425",
|
|
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.
|
|
10
|
-
"@nocobase/utils": "1.
|
|
9
|
+
"@nocobase/logger": "1.4.0-alpha.20240825165425",
|
|
10
|
+
"@nocobase/utils": "1.4.0-alpha.20240825165425",
|
|
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": "dc1bd67309135a872818a919855b45ef7544f689"
|
|
42
42
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { BaseColumnFieldOptions, Field } from './field';
|
|
10
|
-
export declare class DateOnlyField extends Field {
|
|
11
|
-
get dataType(): any;
|
|
12
|
-
}
|
|
13
|
-
export interface DateOnlyFieldOptions extends BaseColumnFieldOptions {
|
|
14
|
-
type: 'dateOnly';
|
|
15
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all)
|
|
17
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
-
};
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
-
for (let key of __getOwnPropNames(from))
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var date_only_field_exports = {};
|
|
29
|
-
__export(date_only_field_exports, {
|
|
30
|
-
DateOnlyField: () => DateOnlyField
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(date_only_field_exports);
|
|
33
|
-
var import_field = require("./field");
|
|
34
|
-
var import_sequelize = require("sequelize");
|
|
35
|
-
const _DateOnlyField = class _DateOnlyField extends import_field.Field {
|
|
36
|
-
get dataType() {
|
|
37
|
-
return import_sequelize.DataTypes.DATEONLY;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
__name(_DateOnlyField, "DateOnlyField");
|
|
41
|
-
let DateOnlyField = _DateOnlyField;
|
|
42
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
-
0 && (module.exports = {
|
|
44
|
-
DateOnlyField
|
|
45
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { DataTypes } from 'sequelize';
|
|
10
|
-
import { DateField } from './date-field';
|
|
11
|
-
import { BaseColumnFieldOptions } from './field';
|
|
12
|
-
export declare class UnixTimestampField extends DateField {
|
|
13
|
-
get dataType(): DataTypes.BigIntDataTypeConstructor;
|
|
14
|
-
additionalSequelizeOptions(): {};
|
|
15
|
-
}
|
|
16
|
-
export interface UnixTimestampFieldOptions extends BaseColumnFieldOptions {
|
|
17
|
-
type: 'unix-timestamp';
|
|
18
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all)
|
|
17
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
-
};
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
-
for (let key of __getOwnPropNames(from))
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var unix_timestamp_field_exports = {};
|
|
29
|
-
__export(unix_timestamp_field_exports, {
|
|
30
|
-
UnixTimestampField: () => UnixTimestampField
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(unix_timestamp_field_exports);
|
|
33
|
-
var import_sequelize = require("sequelize");
|
|
34
|
-
var import_date_field = require("./date-field");
|
|
35
|
-
const _UnixTimestampField = class _UnixTimestampField extends import_date_field.DateField {
|
|
36
|
-
get dataType() {
|
|
37
|
-
return import_sequelize.DataTypes.BIGINT;
|
|
38
|
-
}
|
|
39
|
-
additionalSequelizeOptions() {
|
|
40
|
-
var _a, _b, _c, _d;
|
|
41
|
-
const { name } = this.options;
|
|
42
|
-
let { accuracy } = this.options;
|
|
43
|
-
if ((_b = (_a = this.options) == null ? void 0 : _a.uiSchema["x-component-props"]) == null ? void 0 : _b.accuracy) {
|
|
44
|
-
accuracy = (_d = (_c = this.options) == null ? void 0 : _c.uiSchema["x-component-props"]) == null ? void 0 : _d.accuracy;
|
|
45
|
-
}
|
|
46
|
-
if (!accuracy) {
|
|
47
|
-
accuracy = "second";
|
|
48
|
-
}
|
|
49
|
-
let rationalNumber = 1e3;
|
|
50
|
-
if (accuracy === "millisecond") {
|
|
51
|
-
rationalNumber = 1;
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
get() {
|
|
55
|
-
const value = this.getDataValue(name);
|
|
56
|
-
if (value === null || value === void 0) {
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
return new Date(value * rationalNumber);
|
|
60
|
-
},
|
|
61
|
-
set(value) {
|
|
62
|
-
if (value === null || value === void 0) {
|
|
63
|
-
this.setDataValue(name, value);
|
|
64
|
-
} else {
|
|
65
|
-
this.setDataValue(name, Math.floor(new Date(value).getTime() / rationalNumber));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
__name(_UnixTimestampField, "UnixTimestampField");
|
|
72
|
-
let UnixTimestampField = _UnixTimestampField;
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
-
0 && (module.exports = {
|
|
75
|
-
UnixTimestampField
|
|
76
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { FindOptions, Repository } from '../../repository';
|
|
10
|
-
import Database from '../../database';
|
|
11
|
-
import { Collection } from '../../collection';
|
|
12
|
-
export declare class AdjacencyListRepository extends Repository {
|
|
13
|
-
static queryParentSQL(options: {
|
|
14
|
-
db: Database;
|
|
15
|
-
nodeIds: any[];
|
|
16
|
-
collection: Collection;
|
|
17
|
-
foreignKey: string;
|
|
18
|
-
targetKey: string;
|
|
19
|
-
}): string;
|
|
20
|
-
update(options: any): Promise<any>;
|
|
21
|
-
find(options?: FindOptions & {
|
|
22
|
-
addIndex?: boolean;
|
|
23
|
-
}): Promise<any>;
|
|
24
|
-
private addIndex;
|
|
25
|
-
private querySQL;
|
|
26
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var adjacency_list_repository_exports = {};
|
|
39
|
-
__export(adjacency_list_repository_exports, {
|
|
40
|
-
AdjacencyListRepository: () => AdjacencyListRepository
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(adjacency_list_repository_exports);
|
|
43
|
-
var import_lodash = __toESM(require("lodash"));
|
|
44
|
-
var import_repository = require("../../repository");
|
|
45
|
-
const _AdjacencyListRepository = class _AdjacencyListRepository extends import_repository.Repository {
|
|
46
|
-
static queryParentSQL(options) {
|
|
47
|
-
const { collection, db, nodeIds } = options;
|
|
48
|
-
const tableName = collection.quotedTableName();
|
|
49
|
-
const { foreignKey, targetKey } = options;
|
|
50
|
-
const foreignKeyField = collection.model.rawAttributes[foreignKey].field;
|
|
51
|
-
const targetKeyField = collection.model.rawAttributes[targetKey].field;
|
|
52
|
-
const queryInterface = db.sequelize.getQueryInterface();
|
|
53
|
-
const q = queryInterface.quoteIdentifier.bind(queryInterface);
|
|
54
|
-
return `WITH RECURSIVE cte AS (
|
|
55
|
-
SELECT ${q(targetKeyField)}, ${q(foreignKeyField)}
|
|
56
|
-
FROM ${tableName}
|
|
57
|
-
WHERE ${q(targetKeyField)} IN (${nodeIds.join(",")})
|
|
58
|
-
UNION ALL
|
|
59
|
-
SELECT t.${q(targetKeyField)}, t.${q(foreignKeyField)}
|
|
60
|
-
FROM ${tableName} AS t
|
|
61
|
-
INNER JOIN cte ON t.${q(targetKeyField)} = cte.${q(foreignKeyField)}
|
|
62
|
-
)
|
|
63
|
-
SELECT ${q(targetKeyField)} AS ${q(targetKey)}, ${q(foreignKeyField)} AS ${q(foreignKey)} FROM cte`;
|
|
64
|
-
}
|
|
65
|
-
async update(options) {
|
|
66
|
-
return super.update({
|
|
67
|
-
...options || {},
|
|
68
|
-
addIndex: false
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async find(options = {}) {
|
|
72
|
-
var _a;
|
|
73
|
-
if (options.raw || !options.tree) {
|
|
74
|
-
return await super.find(options);
|
|
75
|
-
}
|
|
76
|
-
const collection = this.collection;
|
|
77
|
-
const primaryKey = collection.model.primaryKeyAttribute;
|
|
78
|
-
if (options.fields && !options.fields.includes(primaryKey)) {
|
|
79
|
-
options.fields.push(primaryKey);
|
|
80
|
-
}
|
|
81
|
-
const parentNodes = await super.find(options);
|
|
82
|
-
if (parentNodes.length === 0) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
const { treeParentField } = collection;
|
|
86
|
-
const foreignKey = treeParentField.options.foreignKey;
|
|
87
|
-
const childrenKey = ((_a = collection.treeChildrenField) == null ? void 0 : _a.name) ?? "children";
|
|
88
|
-
const parentIds = parentNodes.map((node) => node[primaryKey]);
|
|
89
|
-
if (parentIds.length == 0) {
|
|
90
|
-
this.database.logger.warn("parentIds is empty");
|
|
91
|
-
return parentNodes;
|
|
92
|
-
}
|
|
93
|
-
const sql = this.querySQL(parentIds, collection);
|
|
94
|
-
const childNodes = await this.database.sequelize.query(sql, {
|
|
95
|
-
type: "SELECT",
|
|
96
|
-
transaction: options.transaction
|
|
97
|
-
});
|
|
98
|
-
const childIds = childNodes.map((node) => node[primaryKey]);
|
|
99
|
-
const findChildrenOptions = {
|
|
100
|
-
...import_lodash.default.omit(options, ["limit", "offset", "filterByTk"]),
|
|
101
|
-
filter: {
|
|
102
|
-
[primaryKey]: childIds
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
if (findChildrenOptions.fields) {
|
|
106
|
-
[primaryKey, foreignKey].forEach((field) => {
|
|
107
|
-
if (!findChildrenOptions.fields.includes(field)) {
|
|
108
|
-
findChildrenOptions.fields.push(field);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const childInstances = await super.find(findChildrenOptions);
|
|
113
|
-
const nodeMap = {};
|
|
114
|
-
childInstances.forEach((node) => {
|
|
115
|
-
if (!nodeMap[`${node[foreignKey]}`]) {
|
|
116
|
-
nodeMap[`${node[foreignKey]}`] = [];
|
|
117
|
-
}
|
|
118
|
-
nodeMap[`${node[foreignKey]}`].push(node);
|
|
119
|
-
});
|
|
120
|
-
function buildTree(parentId) {
|
|
121
|
-
const children = nodeMap[parentId];
|
|
122
|
-
if (!children) {
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
return children.map((child) => {
|
|
126
|
-
const childrenValues = buildTree(child.id);
|
|
127
|
-
if (childrenValues.length > 0) {
|
|
128
|
-
child.setDataValue(childrenKey, childrenValues);
|
|
129
|
-
}
|
|
130
|
-
return child;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
__name(buildTree, "buildTree");
|
|
134
|
-
for (const parent of parentNodes) {
|
|
135
|
-
const parentId = parent[primaryKey];
|
|
136
|
-
const children = buildTree(parentId);
|
|
137
|
-
if (children.length > 0) {
|
|
138
|
-
parent.setDataValue(childrenKey, children);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
this.addIndex(parentNodes, childrenKey, options);
|
|
142
|
-
return parentNodes;
|
|
143
|
-
}
|
|
144
|
-
addIndex(treeArray, childrenKey, options) {
|
|
145
|
-
function traverse(node, index) {
|
|
146
|
-
if (node._options.includeNames && !node._options.includeNames.includes(childrenKey)) {
|
|
147
|
-
node._options.includeNames.push(childrenKey);
|
|
148
|
-
}
|
|
149
|
-
if (options.addIndex !== false) {
|
|
150
|
-
node.setDataValue("__index", `${index}`);
|
|
151
|
-
}
|
|
152
|
-
const children = node.getDataValue(childrenKey);
|
|
153
|
-
if (children && children.length === 0) {
|
|
154
|
-
node.setDataValue(childrenKey, void 0);
|
|
155
|
-
}
|
|
156
|
-
if (children && children.length > 0) {
|
|
157
|
-
children.forEach((child, i) => {
|
|
158
|
-
traverse(child, `${index}.${childrenKey}.${i}`);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
__name(traverse, "traverse");
|
|
163
|
-
treeArray.forEach((tree, i) => {
|
|
164
|
-
traverse(tree, i);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
querySQL(rootIds, collection) {
|
|
168
|
-
const { treeParentField } = collection;
|
|
169
|
-
const foreignKey = treeParentField.options.foreignKey;
|
|
170
|
-
const foreignKeyField = collection.model.rawAttributes[foreignKey].field;
|
|
171
|
-
const primaryKey = collection.model.primaryKeyAttribute;
|
|
172
|
-
const queryInterface = this.database.sequelize.getQueryInterface();
|
|
173
|
-
const q = queryInterface.quoteIdentifier.bind(queryInterface);
|
|
174
|
-
return `
|
|
175
|
-
WITH RECURSIVE cte AS (SELECT ${q(primaryKey)}, ${q(foreignKeyField)}, 1 AS level
|
|
176
|
-
FROM ${collection.quotedTableName()}
|
|
177
|
-
WHERE ${q(foreignKeyField)} IN (${rootIds.join(",")})
|
|
178
|
-
UNION ALL
|
|
179
|
-
SELECT t.${q(primaryKey)}, t.${q(foreignKeyField)}, cte.level + 1 AS level
|
|
180
|
-
FROM ${collection.quotedTableName()} t
|
|
181
|
-
JOIN cte ON t.${q(foreignKeyField)} = cte.${q(primaryKey)})
|
|
182
|
-
SELECT ${q(primaryKey)}, ${q(foreignKeyField)} as ${q(foreignKey)}, level
|
|
183
|
-
FROM cte
|
|
184
|
-
`;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
__name(_AdjacencyListRepository, "AdjacencyListRepository");
|
|
188
|
-
let AdjacencyListRepository = _AdjacencyListRepository;
|
|
189
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
-
0 && (module.exports = {
|
|
191
|
-
AdjacencyListRepository
|
|
192
|
-
});
|