@nocobase/database 2.1.0-alpha.3 → 2.1.0-alpha.31

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.
@@ -0,0 +1,268 @@
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
+ const ALLOWED_ORDER_DIRECTIONS = ["ASC", "DESC"];
53
+ function createQueryFormatter(database) {
54
+ switch (database.sequelize.getDialect()) {
55
+ case "sqlite":
56
+ return new import_sqlite.SQLiteQueryFormatter(database.sequelize, database.options.rawTimezone);
57
+ case "postgres":
58
+ return new import_postgres.PostgresQueryFormatter(database.sequelize, database.options.rawTimezone);
59
+ case "mysql":
60
+ case "mariadb":
61
+ return new import_mysql.MySQLQueryFormatter(database.sequelize, database.options.rawTimezone);
62
+ case "oracle":
63
+ return new import_oracle.OracleQueryFormatter(database.sequelize, database.options.rawTimezone);
64
+ default:
65
+ return new class extends import_formatter.QueryFormatter {
66
+ formatDate(field, _format, _timezone, _preserveLocalTime) {
67
+ return field;
68
+ }
69
+ formatUnixTimestamp(field, _format, _accuracy, _timezone) {
70
+ return this.sequelize.col(field);
71
+ }
72
+ }(database.sequelize, database.options.rawTimezone);
73
+ }
74
+ }
75
+ __name(createQueryFormatter, "createQueryFormatter");
76
+ function parseSelectedField(database, collection, selected) {
77
+ var _a, _b, _c, _d, _e;
78
+ const collectionName = collection.name;
79
+ const fields = collection.fields;
80
+ let target;
81
+ let name;
82
+ const fieldPath = Array.isArray(selected.field) ? selected.field : selected.field.split(".").filter(Boolean);
83
+ if (fieldPath.length === 1) {
84
+ name = fieldPath[0];
85
+ } else {
86
+ [target, name] = fieldPath;
87
+ }
88
+ const rawAttributes = collection.model.getAttributes();
89
+ let field = ((_a = rawAttributes[name]) == null ? void 0 : _a.field) || name;
90
+ let fieldType = (_b = fields.get(name)) == null ? void 0 : _b.type;
91
+ let fieldOptions = (_c = fields.get(name)) == null ? void 0 : _c.options;
92
+ if (target) {
93
+ const targetField = fields.get(target);
94
+ const targetCollection = database.getCollection(targetField.target);
95
+ const targetFields = targetCollection.fields;
96
+ fieldType = (_d = targetFields.get(name)) == null ? void 0 : _d.type;
97
+ fieldOptions = (_e = targetFields.get(name)) == null ? void 0 : _e.options;
98
+ field = `${target}.${field}`;
99
+ name = `${target}.${name}`;
100
+ } else {
101
+ field = `${collectionName}.${field}`;
102
+ }
103
+ return {
104
+ ...selected,
105
+ field,
106
+ name,
107
+ type: fieldType,
108
+ options: fieldOptions,
109
+ alias: selected.alias || name,
110
+ target
111
+ };
112
+ }
113
+ __name(parseSelectedField, "parseSelectedField");
114
+ function buildQuery(database, collection, options = {}) {
115
+ var _a;
116
+ const sequelize = database.sequelize;
117
+ const formatter = createQueryFormatter(database);
118
+ const measures = (options.measures || []).map((measure) => parseSelectedField(database, collection, measure));
119
+ const dimensions = (options.dimensions || []).map((dimension) => parseSelectedField(database, collection, dimension));
120
+ const orders = (options.orders || []).map((order2) => parseSelectedField(database, collection, order2));
121
+ const models = {};
122
+ [...measures, ...dimensions, ...orders].forEach((item) => {
123
+ var _a2;
124
+ if (item.target && !models[item.target]) {
125
+ models[item.target] = { type: (_a2 = collection.fields.get(item.target)) == null ? void 0 : _a2.type };
126
+ }
127
+ });
128
+ const include = Object.entries(models).map(([target, { type }]) => {
129
+ let includeOptions = {
130
+ association: target,
131
+ attributes: []
132
+ };
133
+ if (type === "belongsToMany") {
134
+ includeOptions.through = { attributes: [] };
135
+ }
136
+ if (type === "belongsToArray") {
137
+ const association = collection.model.associations[target];
138
+ if (association) {
139
+ includeOptions = {
140
+ ...includeOptions,
141
+ ...association.generateInclude()
142
+ };
143
+ }
144
+ }
145
+ return includeOptions;
146
+ });
147
+ const filterParser = new import_filter_parser.default(options.filter, { collection });
148
+ const { where, include: filterInclude } = filterParser.toSequelizeParams();
149
+ if (filterInclude) {
150
+ const stack = [...filterInclude];
151
+ while (stack.length) {
152
+ const item = stack.pop();
153
+ const parentCollection = database.getCollection(item.parentCollection || collection.name);
154
+ const field = parentCollection.fields.get(item.association);
155
+ if ((field == null ? void 0 : field.type) === "belongsToMany") {
156
+ item.through = { attributes: [] };
157
+ }
158
+ if ((field == null ? void 0 : field.target) && ((_a = item.include) == null ? void 0 : _a.length)) {
159
+ for (const child of item.include) {
160
+ child.parentCollection = field.target;
161
+ stack.push(child);
162
+ }
163
+ }
164
+ }
165
+ }
166
+ let hasAgg = false;
167
+ const attributes = [];
168
+ const fieldMap = {};
169
+ const projectedFieldMap = {};
170
+ measures.forEach((measure) => {
171
+ const { field, aggregation, alias, distinct } = measure;
172
+ const col = sequelize.col(field);
173
+ const attribute = [];
174
+ if (aggregation) {
175
+ if (!ALLOWED_AGG_FUNCS.includes(aggregation)) {
176
+ throw new Error(`Invalid aggregation function: ${aggregation}`);
177
+ }
178
+ hasAgg = true;
179
+ attribute.push(sequelize.fn(aggregation, distinct ? sequelize.fn("DISTINCT", col) : col));
180
+ } else {
181
+ attribute.push(col);
182
+ }
183
+ if (alias) {
184
+ attribute.push(alias);
185
+ }
186
+ attributes.push(attribute.length > 1 ? attribute : attribute[0]);
187
+ fieldMap[alias || field] = measure;
188
+ projectedFieldMap[alias || field] = attribute[0];
189
+ });
190
+ const group = [];
191
+ dimensions.forEach((dimension) => {
192
+ const { field, format, alias, type, options: fieldOptions } = dimension;
193
+ const attribute = [];
194
+ if (format) {
195
+ attribute.push(formatter.format({ type, field, format, timezone: options.timezone, fieldOptions }));
196
+ } else {
197
+ attribute.push(sequelize.col(field));
198
+ }
199
+ if (alias) {
200
+ attribute.push(alias);
201
+ }
202
+ attributes.push(attribute.length > 1 ? attribute : attribute[0]);
203
+ if (hasAgg) {
204
+ group.push(attribute[0]);
205
+ }
206
+ fieldMap[alias || field] = dimension;
207
+ projectedFieldMap[alias || field] = attribute[0];
208
+ });
209
+ const order = orders.map((item) => {
210
+ var _a2;
211
+ const alias = sequelize.getQueryInterface().quoteIdentifier(item.alias);
212
+ const projectedField = projectedFieldMap[item.alias] || projectedFieldMap[item.name] || projectedFieldMap[item.field];
213
+ const name = hasAgg ? projectedField || sequelize.literal(alias) : sequelize.col(item.field);
214
+ let sort = ALLOWED_ORDER_DIRECTIONS.includes((_a2 = item.order) == null ? void 0 : _a2.toUpperCase()) ? item.order.toUpperCase() : "ASC";
215
+ if (item.nulls === "first") {
216
+ sort += " NULLS FIRST";
217
+ }
218
+ if (item.nulls === "last") {
219
+ sort += " NULLS LAST";
220
+ }
221
+ return [name, sort];
222
+ });
223
+ const queryOptions = {
224
+ where,
225
+ having: (0, import_having.buildHaving)(database, formatter, fieldMap, options.having, options.timezone),
226
+ attributes,
227
+ include: [...include, ...filterInclude || []],
228
+ group,
229
+ order,
230
+ subQuery: false,
231
+ raw: true
232
+ };
233
+ if (!hasAgg || dimensions.length) {
234
+ queryOptions.limit = options.limit || 2e3;
235
+ queryOptions.offset = options.offset || 0;
236
+ }
237
+ return { queryOptions, fieldMap };
238
+ }
239
+ __name(buildQuery, "buildQuery");
240
+ function normalizeQueryResult(data, fieldMap) {
241
+ const dateTimeTypes = ["date", "datetime", "datetimeTz", "datetimeNoTz"];
242
+ return data.map((record) => {
243
+ Object.entries(record).forEach(([key, value]) => {
244
+ if (value === null || value === void 0) {
245
+ return;
246
+ }
247
+ const field = fieldMap[key];
248
+ const type = field == null ? void 0 : field.type;
249
+ if (["bigInt", "integer", "float", "double", "decimal"].includes(type)) {
250
+ record[key] = Number(value);
251
+ return;
252
+ }
253
+ if (!(field == null ? void 0 : field.format) && dateTimeTypes.includes(type) && !(value instanceof Date)) {
254
+ const dateValue = new Date(value);
255
+ if (!Number.isNaN(dateValue.getTime())) {
256
+ record[key] = dateValue;
257
+ }
258
+ }
259
+ });
260
+ return record;
261
+ });
262
+ }
263
+ __name(normalizeQueryResult, "normalizeQueryResult");
264
+ // Annotate the CommonJS export names for ESM import in node:
265
+ 0 && (module.exports = {
266
+ buildQuery,
267
+ normalizeQueryResult
268
+ });
@@ -0,0 +1,29 @@
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 { Sequelize } from 'sequelize';
10
+ export type Col = ReturnType<typeof Sequelize.col>;
11
+ export type Literal = ReturnType<typeof Sequelize.literal>;
12
+ export type Fn = ReturnType<typeof Sequelize.fn>;
13
+ export declare abstract class QueryFormatter {
14
+ sequelize: Sequelize;
15
+ rawTimezone?: string;
16
+ constructor(sequelize: Sequelize, rawTimezone?: string);
17
+ abstract formatDate(field: Col, format: string, timezone?: string, preserveLocalTime?: boolean): Fn | Col;
18
+ abstract formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): Fn | Literal | Col;
19
+ convertFormat(format: string): string;
20
+ protected getTimezoneByOffset(offset?: string): string;
21
+ protected getOffsetExpression(timezone: string): string;
22
+ format(options: {
23
+ type: string;
24
+ field: string;
25
+ format: string;
26
+ timezone?: string;
27
+ fieldOptions?: any;
28
+ }): import("sequelize/types/utils").Fn | import("sequelize/types/utils").Col | import("sequelize/types/utils").Literal;
29
+ }
@@ -0,0 +1,100 @@
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
+ rawTimezone;
47
+ constructor(sequelize, rawTimezone) {
48
+ this.sequelize = sequelize;
49
+ this.rawTimezone = rawTimezone;
50
+ }
51
+ convertFormat(format) {
52
+ return format;
53
+ }
54
+ getTimezoneByOffset(offset) {
55
+ if (!offset) {
56
+ return;
57
+ }
58
+ if (import_moment_timezone.default.tz.zone(offset)) {
59
+ return offset;
60
+ }
61
+ if (/^[+-]\d{1,2}:\d{2}$/.test(offset)) {
62
+ return offset;
63
+ }
64
+ return;
65
+ }
66
+ getOffsetExpression(timezone) {
67
+ const sign = timezone.charAt(0);
68
+ const value = timezone.slice(1);
69
+ const [hours, minutes] = value.split(":").map(Number);
70
+ return `${sign}${hours * 60 + minutes} minutes`;
71
+ }
72
+ format(options) {
73
+ var _a, _b;
74
+ const { type, field, format, timezone, fieldOptions } = options;
75
+ const col = this.sequelize.col(field);
76
+ switch (type) {
77
+ case "date":
78
+ case "datetime":
79
+ case "datetimeTz":
80
+ return this.formatDate(col, format, timezone);
81
+ case "datetimeNoTz":
82
+ return this.formatDate(col, format, void 0, true);
83
+ case "dateOnly":
84
+ case "time":
85
+ return this.formatDate(col, format);
86
+ case "unixTimestamp": {
87
+ 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";
88
+ return this.formatUnixTimestamp(field, format, accuracy, timezone);
89
+ }
90
+ default:
91
+ return col;
92
+ }
93
+ }
94
+ };
95
+ __name(_QueryFormatter, "QueryFormatter");
96
+ let QueryFormatter = _QueryFormatter;
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ QueryFormatter
100
+ });
@@ -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, _preserveLocalTime?: boolean): 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,70 @@
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, _preserveLocalTime) {
39
+ const fmt = this.convertFormat(format);
40
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
41
+ if (resolvedTimezone) {
42
+ return this.sequelize.fn(
43
+ "date_format",
44
+ this.sequelize.fn("convert_tz", field, process.env.TZ || "UTC", resolvedTimezone),
45
+ fmt
46
+ );
47
+ }
48
+ return this.sequelize.fn("date_format", field, fmt);
49
+ }
50
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
51
+ const fmt = this.convertFormat(format);
52
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
53
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
54
+ const timestamp = accuracy === "millisecond" ? this.sequelize.fn("from_unixtime", this.sequelize.literal(`ROUND(${quoted} / 1000)`)) : this.sequelize.fn("from_unixtime", this.sequelize.col(field));
55
+ if (resolvedTimezone) {
56
+ return this.sequelize.fn(
57
+ "date_format",
58
+ this.sequelize.fn("convert_tz", timestamp, process.env.TZ || "UTC", resolvedTimezone),
59
+ fmt
60
+ );
61
+ }
62
+ 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);
63
+ }
64
+ };
65
+ __name(_MySQLQueryFormatter, "MySQLQueryFormatter");
66
+ let MySQLQueryFormatter = _MySQLQueryFormatter;
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ MySQLQueryFormatter
70
+ });
@@ -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, _preserveLocalTime?: boolean): 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,64 @@
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, _preserveLocalTime) {
39
+ const fmt = this.convertFormat(format);
40
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
41
+ if (resolvedTimezone) {
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 resolvedTimezone = this.getTimezoneByOffset(timezone);
55
+ const literal = resolvedTimezone ? `${timestamp} AT TIME ZONE '${resolvedTimezone}'` : timestamp;
56
+ return this.sequelize.fn("to_char", this.sequelize.literal(literal), this.convertFormat(format));
57
+ }
58
+ };
59
+ __name(_OracleQueryFormatter, "OracleQueryFormatter");
60
+ let OracleQueryFormatter = _OracleQueryFormatter;
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ OracleQueryFormatter
64
+ });
@@ -0,0 +1,15 @@
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
+ private buildTimezoneLiteral;
13
+ formatDate(field: Col, format: string, timezone?: string, _preserveLocalTime?: boolean): import("sequelize/types/utils").Fn;
14
+ formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
15
+ }
@@ -0,0 +1,70 @@
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
+ buildTimezoneLiteral(target) {
39
+ if (/^[+-]\d{1,2}:\d{2}$/.test(target)) {
40
+ return `INTERVAL '${target}'`;
41
+ }
42
+ return `'${target}'`;
43
+ }
44
+ formatDate(field, format, timezone, _preserveLocalTime) {
45
+ const fmt = this.convertFormat(format);
46
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
47
+ if (resolvedTimezone) {
48
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field.col);
49
+ return this.sequelize.fn(
50
+ "to_char",
51
+ this.sequelize.literal(`timezone(${this.buildTimezoneLiteral(resolvedTimezone)}, ${quoted})`),
52
+ fmt
53
+ );
54
+ }
55
+ return this.sequelize.fn("to_char", field, fmt);
56
+ }
57
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
58
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
59
+ const timestamp = accuracy === "millisecond" ? `to_timestamp(ROUND(${quoted} / 1000))` : `to_timestamp(${quoted})`;
60
+ const resolvedTimezone = this.getTimezoneByOffset(timezone);
61
+ const literal = resolvedTimezone ? `timezone(${this.buildTimezoneLiteral(resolvedTimezone)}, ${timestamp})` : timestamp;
62
+ return this.sequelize.fn("to_char", this.sequelize.literal(literal), this.convertFormat(format));
63
+ }
64
+ };
65
+ __name(_PostgresQueryFormatter, "PostgresQueryFormatter");
66
+ let PostgresQueryFormatter = _PostgresQueryFormatter;
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ PostgresQueryFormatter
70
+ });
@@ -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, preserveLocalTime?: boolean): import("sequelize/types/utils").Fn;
13
+ formatUnixTimestamp(field: string, format: string, accuracy?: 'second' | 'millisecond', timezone?: string): import("sequelize/types/utils").Fn;
14
+ }