@nocobase/database 2.1.0-alpha.12 → 2.1.0-alpha.14

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.
@@ -43,7 +43,7 @@ const _RelationField = class _RelationField extends import_field.Field {
43
43
  return this.options.foreignKey;
44
44
  }
45
45
  get sourceKey() {
46
- return this.options.sourceKey || this.collection.model.primaryKeyAttribute;
46
+ return this.options.sourceKey || this.collection.filterTargetKey;
47
47
  }
48
48
  get targetKey() {
49
49
  return this.options.targetKey || this.TargetModel.primaryKeyAttribute;
package/lib/index.d.ts CHANGED
@@ -32,6 +32,9 @@ export * from './relation-repository/hasmany-repository';
32
32
  export * from './relation-repository/hasone-repository';
33
33
  export * from './relation-repository/multiple-relation-repository';
34
34
  export * from './relation-repository/single-relation-repository';
35
+ export * from './query/builder';
36
+ export * from './query/formatter';
37
+ export * from './query/types';
35
38
  export * from './repository';
36
39
  export * from './relation-repository/relation-repository';
37
40
  export { default as sqlParser, SQLParserTypes } from './sql-parser';
package/lib/index.js CHANGED
@@ -93,6 +93,9 @@ __reExport(src_exports, require("./relation-repository/hasmany-repository"), mod
93
93
  __reExport(src_exports, require("./relation-repository/hasone-repository"), module.exports);
94
94
  __reExport(src_exports, require("./relation-repository/multiple-relation-repository"), module.exports);
95
95
  __reExport(src_exports, require("./relation-repository/single-relation-repository"), module.exports);
96
+ __reExport(src_exports, require("./query/builder"), module.exports);
97
+ __reExport(src_exports, require("./query/formatter"), module.exports);
98
+ __reExport(src_exports, require("./query/types"), module.exports);
96
99
  __reExport(src_exports, require("./repository"), module.exports);
97
100
  __reExport(src_exports, require("./relation-repository/relation-repository"), module.exports);
98
101
  var import_sql_parser = __toESM(require("./sql-parser"));
@@ -157,6 +160,9 @@ var import_filter_include = require("./utils/filter-include");
157
160
  ...require("./relation-repository/hasone-repository"),
158
161
  ...require("./relation-repository/multiple-relation-repository"),
159
162
  ...require("./relation-repository/single-relation-repository"),
163
+ ...require("./query/builder"),
164
+ ...require("./query/formatter"),
165
+ ...require("./query/types"),
160
166
  ...require("./repository"),
161
167
  ...require("./relation-repository/relation-repository"),
162
168
  ...require("./update-associations"),
@@ -0,0 +1,17 @@
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 as SequelizeFindOptions } from 'sequelize';
10
+ import { Collection } from '../collection';
11
+ import { Database } from '../database';
12
+ import { QueryOptions } from './types';
13
+ export declare function buildQuery(database: Database, collection: Collection, options?: QueryOptions): {
14
+ queryOptions: SequelizeFindOptions<any>;
15
+ fieldMap: Record<string, any>;
16
+ };
17
+ export declare function normalizeQueryResult(data: any[], fieldMap: Record<string, any>): any[];
@@ -0,0 +1,254 @@
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 builder_exports = {};
39
+ __export(builder_exports, {
40
+ buildQuery: () => buildQuery,
41
+ normalizeQueryResult: () => normalizeQueryResult
42
+ });
43
+ module.exports = __toCommonJS(builder_exports);
44
+ var import_filter_parser = __toESM(require("../filter-parser"));
45
+ var import_formatter = require("./formatter");
46
+ var import_mysql = require("./formatters/mysql");
47
+ var import_oracle = require("./formatters/oracle");
48
+ var import_postgres = require("./formatters/postgres");
49
+ var import_sqlite = require("./formatters/sqlite");
50
+ var import_having = require("./having");
51
+ const ALLOWED_AGG_FUNCS = ["sum", "count", "avg", "min", "max"];
52
+ function createQueryFormatter(database) {
53
+ switch (database.sequelize.getDialect()) {
54
+ case "sqlite":
55
+ return new import_sqlite.SQLiteQueryFormatter(database.sequelize);
56
+ case "postgres":
57
+ return new import_postgres.PostgresQueryFormatter(database.sequelize);
58
+ case "mysql":
59
+ case "mariadb":
60
+ return new import_mysql.MySQLQueryFormatter(database.sequelize);
61
+ case "oracle":
62
+ return new import_oracle.OracleQueryFormatter(database.sequelize);
63
+ default:
64
+ return new class extends import_formatter.QueryFormatter {
65
+ formatDate(field, _format, _timezone) {
66
+ return field;
67
+ }
68
+ formatUnixTimestamp(field, _format, _accuracy, _timezone) {
69
+ return this.sequelize.col(field);
70
+ }
71
+ }(database.sequelize);
72
+ }
73
+ }
74
+ __name(createQueryFormatter, "createQueryFormatter");
75
+ function parseSelectedField(database, collection, selected) {
76
+ var _a, _b, _c, _d, _e;
77
+ const collectionName = collection.name;
78
+ const fields = collection.fields;
79
+ let target;
80
+ let name;
81
+ const fieldPath = Array.isArray(selected.field) ? selected.field : selected.field.split(".").filter(Boolean);
82
+ if (fieldPath.length === 1) {
83
+ name = fieldPath[0];
84
+ } else {
85
+ [target, name] = fieldPath;
86
+ }
87
+ const rawAttributes = collection.model.getAttributes();
88
+ let field = ((_a = rawAttributes[name]) == null ? void 0 : _a.field) || name;
89
+ let fieldType = (_b = fields.get(name)) == null ? void 0 : _b.type;
90
+ let fieldOptions = (_c = fields.get(name)) == null ? void 0 : _c.options;
91
+ if (target) {
92
+ const targetField = fields.get(target);
93
+ const targetCollection = database.getCollection(targetField.target);
94
+ const targetFields = targetCollection.fields;
95
+ fieldType = (_d = targetFields.get(name)) == null ? void 0 : _d.type;
96
+ fieldOptions = (_e = targetFields.get(name)) == null ? void 0 : _e.options;
97
+ field = `${target}.${field}`;
98
+ name = `${target}.${name}`;
99
+ } else {
100
+ field = `${collectionName}.${field}`;
101
+ }
102
+ return {
103
+ ...selected,
104
+ field,
105
+ name,
106
+ type: fieldType,
107
+ options: fieldOptions,
108
+ alias: selected.alias || name,
109
+ target
110
+ };
111
+ }
112
+ __name(parseSelectedField, "parseSelectedField");
113
+ function buildQuery(database, collection, options = {}) {
114
+ var _a;
115
+ const sequelize = database.sequelize;
116
+ const formatter = createQueryFormatter(database);
117
+ const measures = (options.measures || []).map((measure) => parseSelectedField(database, collection, measure));
118
+ const dimensions = (options.dimensions || []).map((dimension) => parseSelectedField(database, collection, dimension));
119
+ const orders = (options.orders || []).map((order2) => parseSelectedField(database, collection, order2));
120
+ const models = {};
121
+ [...measures, ...dimensions, ...orders].forEach((item) => {
122
+ var _a2;
123
+ if (item.target && !models[item.target]) {
124
+ models[item.target] = { type: (_a2 = collection.fields.get(item.target)) == null ? void 0 : _a2.type };
125
+ }
126
+ });
127
+ const include = Object.entries(models).map(([target, { type }]) => {
128
+ let includeOptions = {
129
+ association: target,
130
+ attributes: []
131
+ };
132
+ if (type === "belongsToMany") {
133
+ includeOptions.through = { attributes: [] };
134
+ }
135
+ if (type === "belongsToArray") {
136
+ const association = collection.model.associations[target];
137
+ if (association) {
138
+ includeOptions = {
139
+ ...includeOptions,
140
+ ...association.generateInclude()
141
+ };
142
+ }
143
+ }
144
+ return includeOptions;
145
+ });
146
+ const filterParser = new import_filter_parser.default(options.filter, { collection });
147
+ const { where, include: filterInclude } = filterParser.toSequelizeParams();
148
+ if (filterInclude) {
149
+ const stack = [...filterInclude];
150
+ while (stack.length) {
151
+ const item = stack.pop();
152
+ const parentCollection = database.getCollection(item.parentCollection || collection.name);
153
+ const field = parentCollection.fields.get(item.association);
154
+ if ((field == null ? void 0 : field.type) === "belongsToMany") {
155
+ item.through = { attributes: [] };
156
+ }
157
+ if ((field == null ? void 0 : field.target) && ((_a = item.include) == null ? void 0 : _a.length)) {
158
+ for (const child of item.include) {
159
+ child.parentCollection = field.target;
160
+ stack.push(child);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ let hasAgg = false;
166
+ const attributes = [];
167
+ const fieldMap = {};
168
+ measures.forEach((measure) => {
169
+ const { field, aggregation, alias, distinct } = measure;
170
+ const col = sequelize.col(field);
171
+ const attribute = [];
172
+ if (aggregation) {
173
+ if (!ALLOWED_AGG_FUNCS.includes(aggregation)) {
174
+ throw new Error(`Invalid aggregation function: ${aggregation}`);
175
+ }
176
+ hasAgg = true;
177
+ attribute.push(sequelize.fn(aggregation, distinct ? sequelize.fn("DISTINCT", col) : col));
178
+ } else {
179
+ attribute.push(col);
180
+ }
181
+ if (alias) {
182
+ attribute.push(alias);
183
+ }
184
+ attributes.push(attribute.length > 1 ? attribute : attribute[0]);
185
+ fieldMap[alias || field] = measure;
186
+ });
187
+ const group = [];
188
+ dimensions.forEach((dimension) => {
189
+ const { field, format, alias, type, options: fieldOptions } = dimension;
190
+ const attribute = [];
191
+ if (format) {
192
+ attribute.push(formatter.format({ type, field, format, timezone: options.timezone, fieldOptions }));
193
+ } else {
194
+ attribute.push(sequelize.col(field));
195
+ }
196
+ if (alias) {
197
+ attribute.push(alias);
198
+ }
199
+ attributes.push(attribute.length > 1 ? attribute : attribute[0]);
200
+ if (hasAgg) {
201
+ group.push(attribute[0]);
202
+ }
203
+ fieldMap[alias || field] = dimension;
204
+ });
205
+ const order = orders.map((item) => {
206
+ const alias = sequelize.getQueryInterface().quoteIdentifier(item.alias);
207
+ const name = hasAgg ? sequelize.literal(alias) : sequelize.col(item.field);
208
+ let sort = (item.order || "ASC").toUpperCase();
209
+ if (item.nulls === "first") {
210
+ sort += " NULLS FIRST";
211
+ }
212
+ if (item.nulls === "last") {
213
+ sort += " NULLS LAST";
214
+ }
215
+ return [name, sort];
216
+ });
217
+ const queryOptions = {
218
+ where,
219
+ having: (0, import_having.buildHaving)(database, formatter, fieldMap, options.having, options.timezone),
220
+ attributes,
221
+ include: [...include, ...filterInclude || []],
222
+ group,
223
+ order,
224
+ subQuery: false,
225
+ raw: true
226
+ };
227
+ if (!hasAgg || dimensions.length) {
228
+ queryOptions.limit = options.limit || 2e3;
229
+ queryOptions.offset = options.offset || 0;
230
+ }
231
+ return { queryOptions, fieldMap };
232
+ }
233
+ __name(buildQuery, "buildQuery");
234
+ function normalizeQueryResult(data, fieldMap) {
235
+ return data.map((record) => {
236
+ Object.entries(record).forEach(([key, value]) => {
237
+ var _a;
238
+ if (value === null || value === void 0) {
239
+ return;
240
+ }
241
+ const type = (_a = fieldMap[key]) == null ? void 0 : _a.type;
242
+ if (["bigInt", "integer", "float", "double", "decimal"].includes(type)) {
243
+ record[key] = Number(value);
244
+ }
245
+ });
246
+ return record;
247
+ });
248
+ }
249
+ __name(normalizeQueryResult, "normalizeQueryResult");
250
+ // Annotate the CommonJS export names for ESM import in node:
251
+ 0 && (module.exports = {
252
+ buildQuery,
253
+ normalizeQueryResult
254
+ });
@@ -0,0 +1,20 @@
1
+ import { Sequelize } from 'sequelize';
2
+ export type Col = ReturnType<typeof Sequelize.col>;
3
+ export type Literal = ReturnType<typeof Sequelize.literal>;
4
+ export type Fn = ReturnType<typeof Sequelize.fn>;
5
+ export declare abstract class QueryFormatter {
6
+ sequelize: Sequelize;
7
+ constructor(sequelize: Sequelize);
8
+ abstract formatDate(field: Col, format: string, timezone?: string): Fn | Col;
9
+ abstract formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): Fn | Literal | Col;
10
+ convertFormat(format: string): string;
11
+ protected getTimezoneByOffset(offset: string): string;
12
+ protected getOffsetExpression(timezone: string): string;
13
+ format(options: {
14
+ type: string;
15
+ field: string;
16
+ format: string;
17
+ timezone?: string;
18
+ fieldOptions?: any;
19
+ }): import("sequelize/types/utils").Fn | import("sequelize/types/utils").Col | import("sequelize/types/utils").Literal;
20
+ }
@@ -0,0 +1,94 @@
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 formatter_exports = {};
39
+ __export(formatter_exports, {
40
+ QueryFormatter: () => QueryFormatter
41
+ });
42
+ module.exports = __toCommonJS(formatter_exports);
43
+ var import_moment_timezone = __toESM(require("moment-timezone"));
44
+ const _QueryFormatter = class _QueryFormatter {
45
+ sequelize;
46
+ constructor(sequelize) {
47
+ this.sequelize = sequelize;
48
+ }
49
+ convertFormat(format) {
50
+ return format;
51
+ }
52
+ getTimezoneByOffset(offset) {
53
+ if (!/^[+-]\d{1,2}:\d{2}$/.test(offset)) {
54
+ return offset;
55
+ }
56
+ const offsetMinutes = import_moment_timezone.default.duration(offset).asMinutes();
57
+ return import_moment_timezone.default.tz.names().find((timezone) => {
58
+ return import_moment_timezone.default.tz(timezone).utcOffset() === offsetMinutes;
59
+ });
60
+ }
61
+ getOffsetExpression(timezone) {
62
+ const sign = timezone.charAt(0);
63
+ const value = timezone.slice(1);
64
+ const [hours, minutes] = value.split(":").map(Number);
65
+ return `${sign}${hours * 60 + minutes} minutes`;
66
+ }
67
+ format(options) {
68
+ var _a, _b;
69
+ const { type, field, format, timezone, fieldOptions } = options;
70
+ const col = this.sequelize.col(field);
71
+ switch (type) {
72
+ case "date":
73
+ case "datetime":
74
+ case "datetimeTz":
75
+ return this.formatDate(col, format, timezone);
76
+ case "datetimeNoTz":
77
+ case "dateOnly":
78
+ case "time":
79
+ return this.formatDate(col, format);
80
+ case "unixTimestamp": {
81
+ const accuracy = ((_b = (_a = fieldOptions == null ? void 0 : fieldOptions.uiSchema) == null ? void 0 : _a["x-component-props"]) == null ? void 0 : _b.accuracy) || (fieldOptions == null ? void 0 : fieldOptions.accuracy) || "second";
82
+ return this.formatUnixTimestamp(field, format, accuracy, timezone);
83
+ }
84
+ default:
85
+ return col;
86
+ }
87
+ }
88
+ };
89
+ __name(_QueryFormatter, "QueryFormatter");
90
+ let QueryFormatter = _QueryFormatter;
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ QueryFormatter
94
+ });
@@ -0,0 +1,14 @@
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 { QueryFormatter, Col } from '../formatter';
10
+ export declare class MySQLQueryFormatter extends QueryFormatter {
11
+ convertFormat(format: string): string;
12
+ formatDate(field: Col, format: string, timezone?: string): import("sequelize/types/utils").Fn;
13
+ formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
14
+ }
@@ -0,0 +1,68 @@
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 mysql_exports = {};
29
+ __export(mysql_exports, {
30
+ MySQLQueryFormatter: () => MySQLQueryFormatter
31
+ });
32
+ module.exports = __toCommonJS(mysql_exports);
33
+ var import_formatter = require("../formatter");
34
+ const _MySQLQueryFormatter = class _MySQLQueryFormatter extends import_formatter.QueryFormatter {
35
+ convertFormat(format) {
36
+ return format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%i").replace(/ss/g, "%S");
37
+ }
38
+ formatDate(field, format, timezone) {
39
+ const fmt = this.convertFormat(format);
40
+ if (timezone) {
41
+ return this.sequelize.fn(
42
+ "date_format",
43
+ this.sequelize.fn("convert_tz", field, process.env.TZ || "UTC", timezone),
44
+ fmt
45
+ );
46
+ }
47
+ return this.sequelize.fn("date_format", field, fmt);
48
+ }
49
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
50
+ const fmt = this.convertFormat(format);
51
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
52
+ const timestamp = accuracy === "millisecond" ? this.sequelize.fn("from_unixtime", this.sequelize.literal(`ROUND(${quoted} / 1000)`)) : this.sequelize.fn("from_unixtime", this.sequelize.col(field));
53
+ if (timezone) {
54
+ return this.sequelize.fn(
55
+ "date_format",
56
+ this.sequelize.fn("convert_tz", timestamp, process.env.TZ || "UTC", timezone),
57
+ fmt
58
+ );
59
+ }
60
+ return accuracy === "millisecond" ? this.sequelize.fn("from_unixtime", this.sequelize.literal(`ROUND(${quoted} / 1000)`), fmt) : this.sequelize.fn("from_unixtime", this.sequelize.col(field), fmt);
61
+ }
62
+ };
63
+ __name(_MySQLQueryFormatter, "MySQLQueryFormatter");
64
+ let MySQLQueryFormatter = _MySQLQueryFormatter;
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ MySQLQueryFormatter
68
+ });
@@ -0,0 +1,14 @@
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 { QueryFormatter, Col } from '../formatter';
10
+ export declare class OracleQueryFormatter extends QueryFormatter {
11
+ convertFormat(format: string): string;
12
+ formatDate(field: Col, format: string, timezone?: string): import("sequelize/types/utils").Fn;
13
+ formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
14
+ }
@@ -0,0 +1,63 @@
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 oracle_exports = {};
29
+ __export(oracle_exports, {
30
+ OracleQueryFormatter: () => OracleQueryFormatter
31
+ });
32
+ module.exports = __toCommonJS(oracle_exports);
33
+ var import_formatter = require("../formatter");
34
+ const _OracleQueryFormatter = class _OracleQueryFormatter extends import_formatter.QueryFormatter {
35
+ convertFormat(format) {
36
+ return format.replace(/hh/g, "HH24").replace(/mm/g, "MI").replace(/ss/g, "SS");
37
+ }
38
+ formatDate(field, format, timezone) {
39
+ const fmt = this.convertFormat(format);
40
+ if (timezone) {
41
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
42
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field.col);
43
+ return this.sequelize.fn(
44
+ "to_char",
45
+ this.sequelize.literal(`(${quoted} AT TIME ZONE '${resolvedTimezone}')`),
46
+ fmt
47
+ );
48
+ }
49
+ return this.sequelize.fn("to_char", field, fmt);
50
+ }
51
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
52
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
53
+ const timestamp = accuracy === "millisecond" ? `to_timestamp(ROUND(${quoted} / 1000))` : `to_timestamp(${quoted})`;
54
+ const literal = timezone ? `${timestamp} AT TIME ZONE '${this.getTimezoneByOffset(timezone)}'` : timestamp;
55
+ return this.sequelize.fn("to_char", this.sequelize.literal(literal), this.convertFormat(format));
56
+ }
57
+ };
58
+ __name(_OracleQueryFormatter, "OracleQueryFormatter");
59
+ let OracleQueryFormatter = _OracleQueryFormatter;
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ OracleQueryFormatter
63
+ });
@@ -0,0 +1,14 @@
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 { QueryFormatter, Col } from '../formatter';
10
+ export declare class PostgresQueryFormatter extends QueryFormatter {
11
+ convertFormat(format: string): string;
12
+ formatDate(field: Col, format: string, timezone?: string): import("sequelize/types/utils").Fn;
13
+ formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
14
+ }
@@ -0,0 +1,63 @@
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 postgres_exports = {};
29
+ __export(postgres_exports, {
30
+ PostgresQueryFormatter: () => PostgresQueryFormatter
31
+ });
32
+ module.exports = __toCommonJS(postgres_exports);
33
+ var import_formatter = require("../formatter");
34
+ const _PostgresQueryFormatter = class _PostgresQueryFormatter extends import_formatter.QueryFormatter {
35
+ convertFormat(format) {
36
+ return format.replace(/hh/g, "HH24").replace(/mm/g, "MI").replace(/ss/g, "SS");
37
+ }
38
+ formatDate(field, format, timezone) {
39
+ const fmt = this.convertFormat(format);
40
+ if (timezone) {
41
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
42
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field.col);
43
+ return this.sequelize.fn(
44
+ "to_char",
45
+ this.sequelize.literal(`(${quoted} AT TIME ZONE '${resolvedTimezone}')`),
46
+ fmt
47
+ );
48
+ }
49
+ return this.sequelize.fn("to_char", field, fmt);
50
+ }
51
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
52
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
53
+ const timestamp = accuracy === "millisecond" ? `to_timestamp(ROUND(${quoted} / 1000))` : `to_timestamp(${quoted})`;
54
+ const literal = timezone ? `${timestamp} AT TIME ZONE '${this.getTimezoneByOffset(timezone)}'` : timestamp;
55
+ return this.sequelize.fn("to_char", this.sequelize.literal(literal), this.convertFormat(format));
56
+ }
57
+ };
58
+ __name(_PostgresQueryFormatter, "PostgresQueryFormatter");
59
+ let PostgresQueryFormatter = _PostgresQueryFormatter;
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ PostgresQueryFormatter
63
+ });
@@ -0,0 +1,14 @@
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 { QueryFormatter, Col } from '../formatter';
10
+ export declare class SQLiteQueryFormatter extends QueryFormatter {
11
+ convertFormat(format: string): string;
12
+ formatDate(field: Col, format: string, timezone?: string): import("sequelize/types/utils").Fn;
13
+ formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
14
+ }
@@ -0,0 +1,60 @@
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 sqlite_exports = {};
29
+ __export(sqlite_exports, {
30
+ SQLiteQueryFormatter: () => SQLiteQueryFormatter
31
+ });
32
+ module.exports = __toCommonJS(sqlite_exports);
33
+ var import_formatter = require("../formatter");
34
+ const _SQLiteQueryFormatter = class _SQLiteQueryFormatter extends import_formatter.QueryFormatter {
35
+ convertFormat(format) {
36
+ return format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%M").replace(/ss/g, "%S");
37
+ }
38
+ formatDate(field, format, timezone) {
39
+ const fmt = this.convertFormat(format);
40
+ if (timezone) {
41
+ return this.sequelize.fn("strftime", fmt, field, this.getOffsetExpression(timezone));
42
+ }
43
+ return this.sequelize.fn("strftime", fmt, field);
44
+ }
45
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
46
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
47
+ const base = accuracy === "millisecond" ? this.sequelize.literal(`ROUND(${quoted} / 1000)`) : this.sequelize.col(field);
48
+ const args = [base, "unixepoch"];
49
+ if (timezone) {
50
+ args.push(this.getOffsetExpression(timezone));
51
+ }
52
+ return this.sequelize.fn("strftime", this.convertFormat(format), this.sequelize.fn("DATETIME", ...args));
53
+ }
54
+ };
55
+ __name(_SQLiteQueryFormatter, "SQLiteQueryFormatter");
56
+ let SQLiteQueryFormatter = _SQLiteQueryFormatter;
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ SQLiteQueryFormatter
60
+ });
@@ -0,0 +1,22 @@
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 { WhereOptions } from 'sequelize';
10
+ import { Database } from '../database';
11
+ import { QueryFormatter } from './formatter';
12
+ type QueryFieldMeta = {
13
+ field: string;
14
+ alias?: string;
15
+ aggregation?: string;
16
+ distinct?: boolean;
17
+ format?: string;
18
+ type?: string;
19
+ options?: any;
20
+ };
21
+ export declare function buildHaving(database: Database, formatter: QueryFormatter, fieldMap: Record<string, QueryFieldMeta>, having?: any, timezone?: string): WhereOptions;
22
+ export {};
@@ -0,0 +1,112 @@
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 having_exports = {};
29
+ __export(having_exports, {
30
+ buildHaving: () => buildHaving
31
+ });
32
+ module.exports = __toCommonJS(having_exports);
33
+ var import_lodash = require("lodash");
34
+ var import_sequelize = require("sequelize");
35
+ function buildFieldExpression(database, formatter, fieldMap, key, timezone) {
36
+ const meta = fieldMap[key];
37
+ if (!meta) {
38
+ throw new Error(`Invalid having field: ${key}`);
39
+ }
40
+ const col = database.sequelize.col(meta.field);
41
+ if (meta.aggregation) {
42
+ return database.sequelize.fn(meta.aggregation, meta.distinct ? database.sequelize.fn("DISTINCT", col) : col);
43
+ }
44
+ if (meta.format) {
45
+ return formatter.format({
46
+ type: meta.type,
47
+ field: meta.field,
48
+ format: meta.format,
49
+ timezone,
50
+ fieldOptions: meta.options
51
+ });
52
+ }
53
+ return col;
54
+ }
55
+ __name(buildFieldExpression, "buildFieldExpression");
56
+ function isOperatorCondition(database, value) {
57
+ return (0, import_lodash.isPlainObject)(value) && Object.keys(value).some((key) => database.operators.has(key));
58
+ }
59
+ __name(isOperatorCondition, "isOperatorCondition");
60
+ function buildFieldCondition(database, formatter, fieldMap, key, value, timezone) {
61
+ const field = buildFieldExpression(database, formatter, fieldMap, key, timezone);
62
+ if (!isOperatorCondition(database, value)) {
63
+ return database.sequelize.where(field, { [import_sequelize.Op.eq]: value });
64
+ }
65
+ const condition = {};
66
+ for (const [operatorKey, operatorValue] of Object.entries(value)) {
67
+ const operator = database.operators.get(operatorKey);
68
+ if (typeof operator !== "symbol") {
69
+ throw new Error(`Unsupported having operator: ${operatorKey}`);
70
+ }
71
+ condition[operator] = operatorValue;
72
+ }
73
+ return database.sequelize.where(field, condition);
74
+ }
75
+ __name(buildFieldCondition, "buildFieldCondition");
76
+ function buildHavingNode(database, formatter, fieldMap, node, timezone) {
77
+ if (!(0, import_lodash.isPlainObject)(node)) {
78
+ throw new Error("Having must be an object");
79
+ }
80
+ const conditions = [];
81
+ for (const [key, value] of Object.entries(node)) {
82
+ if ((key === "$and" || key === "$or") && Array.isArray(value)) {
83
+ const operator = database.operators.get(key);
84
+ if (typeof operator !== "symbol") {
85
+ throw new Error(`Unsupported having operator: ${key}`);
86
+ }
87
+ conditions.push({
88
+ [operator]: value.map((item) => buildHavingNode(database, formatter, fieldMap, item, timezone))
89
+ });
90
+ continue;
91
+ }
92
+ conditions.push(buildFieldCondition(database, formatter, fieldMap, key, value, timezone));
93
+ }
94
+ if (conditions.length === 1) {
95
+ return conditions[0];
96
+ }
97
+ return {
98
+ [import_sequelize.Op.and]: conditions
99
+ };
100
+ }
101
+ __name(buildHavingNode, "buildHavingNode");
102
+ function buildHaving(database, formatter, fieldMap, having, timezone) {
103
+ if (!having) {
104
+ return void 0;
105
+ }
106
+ return buildHavingNode(database, formatter, fieldMap, having, timezone);
107
+ }
108
+ __name(buildHaving, "buildHaving");
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ buildHaving
112
+ });
@@ -0,0 +1,40 @@
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
+ export type QueryField = string | string[];
10
+ export interface QueryMeasure {
11
+ field: QueryField;
12
+ type?: string;
13
+ aggregation?: string;
14
+ alias?: string;
15
+ distinct?: boolean;
16
+ }
17
+ export interface QueryDimension {
18
+ field: QueryField;
19
+ type?: string;
20
+ alias?: string;
21
+ format?: string;
22
+ options?: any;
23
+ }
24
+ export interface QueryOrder {
25
+ field: QueryField;
26
+ alias?: string;
27
+ order?: 'asc' | 'desc';
28
+ nulls?: 'default' | 'first' | 'last';
29
+ }
30
+ export interface QueryOptions {
31
+ measures?: QueryMeasure[];
32
+ dimensions?: QueryDimension[];
33
+ orders?: QueryOrder[];
34
+ filter?: any;
35
+ having?: any;
36
+ limit?: number;
37
+ offset?: number;
38
+ timezone?: string;
39
+ context?: any;
40
+ }
@@ -0,0 +1,24 @@
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 __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var types_exports = {};
24
+ module.exports = __toCommonJS(types_exports);
@@ -15,6 +15,7 @@ import { Database } from './database';
15
15
  import { ArrayFieldRepository } from './field-repository/array-field-repository';
16
16
  import { Model } from './model';
17
17
  import operators from './operators';
18
+ import type { QueryOptions } from './query/types';
18
19
  import { BelongsToManyRepository } from './relation-repository/belongs-to-many-repository';
19
20
  import { BelongsToRepository } from './relation-repository/belongs-to-repository';
20
21
  import { HasManyRepository } from './relation-repository/hasmany-repository';
@@ -136,6 +137,8 @@ export interface AggregateOptions {
136
137
  filter?: Filter;
137
138
  distinct?: boolean;
138
139
  }
140
+ export interface QueryOptionsWithTransaction extends QueryOptions, Transactionable {
141
+ }
139
142
  export interface FirstOrCreateOptions extends Transactionable {
140
143
  filterKeys: string[];
141
144
  values?: Values;
@@ -156,6 +159,7 @@ export declare class Repository<TModelAttributes extends {} = any, TCreationAttr
156
159
  count(countOptions?: CountOptions): Promise<number>;
157
160
  getEstimatedRowCount(): Promise<number>;
158
161
  private getOracleSchema;
162
+ query(options?: QueryOptionsWithTransaction): Promise<any[]>;
159
163
  aggregate(options: AggregateOptions & {
160
164
  optionsTransformer?: (options: any) => any;
161
165
  }): Promise<any>;
package/lib/repository.js CHANGED
@@ -65,6 +65,7 @@ var import_array_field_repository = require("./field-repository/array-field-repo
65
65
  var import_fields = require("./fields");
66
66
  var import_filter_parser = __toESM(require("./filter-parser"));
67
67
  var import_options_parser = require("./options-parser");
68
+ var import_builder = require("./query/builder");
68
69
  var import_belongs_to_many_repository = require("./relation-repository/belongs-to-many-repository");
69
70
  var import_belongs_to_repository = require("./relation-repository/belongs-to-repository");
70
71
  var import_hasmany_repository = require("./relation-repository/hasmany-repository");
@@ -240,6 +241,21 @@ const _Repository = class _Repository {
240
241
  });
241
242
  return (result == null ? void 0 : result["USER"]) ?? "";
242
243
  }
244
+ async query(options = {}) {
245
+ const transaction2 = await this.getTransaction(options);
246
+ const { queryOptions, fieldMap } = (0, import_builder.buildQuery)(this.database, this.collection, options);
247
+ const finalQueryOptions = {
248
+ ...queryOptions,
249
+ transaction: transaction2
250
+ };
251
+ if (Array.isArray(finalQueryOptions.include) && finalQueryOptions.include.length > 0) {
252
+ finalQueryOptions.include = (0, import_utils2.processIncludes)(finalQueryOptions.include, this.collection.model);
253
+ } else {
254
+ delete finalQueryOptions.include;
255
+ }
256
+ const data = await this.model.findAll(finalQueryOptions);
257
+ return (0, import_builder.normalizeQueryResult)(data, fieldMap);
258
+ }
243
259
  async aggregate(options) {
244
260
  var _a;
245
261
  const { method, field } = options;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/database",
3
- "version": "2.1.0-alpha.12",
3
+ "version": "2.1.0-alpha.14",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
- "@nocobase/logger": "2.1.0-alpha.12",
10
- "@nocobase/utils": "2.1.0-alpha.12",
9
+ "@nocobase/logger": "2.1.0-alpha.14",
10
+ "@nocobase/utils": "2.1.0-alpha.14",
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": "f12c4a75470590b1670ce54510b96ef94c2cd7a2"
41
+ "gitHead": "d8735b541de0ff9557bba704de49c799b4962672"
42
42
  }