@nocobase/database 2.1.0-alpha.2 → 2.1.0-alpha.21

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,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,103 @@
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;
63
+ }
64
+ const offsetMinutes = import_moment_timezone.default.duration(offset).asMinutes();
65
+ return import_moment_timezone.default.tz.names().find((timezone) => {
66
+ return import_moment_timezone.default.tz(timezone).utcOffset() === offsetMinutes;
67
+ });
68
+ }
69
+ getOffsetExpression(timezone) {
70
+ const sign = timezone.charAt(0);
71
+ const value = timezone.slice(1);
72
+ const [hours, minutes] = value.split(":").map(Number);
73
+ return `${sign}${hours * 60 + minutes} minutes`;
74
+ }
75
+ format(options) {
76
+ var _a, _b;
77
+ const { type, field, format, timezone, fieldOptions } = options;
78
+ const col = this.sequelize.col(field);
79
+ switch (type) {
80
+ case "date":
81
+ case "datetime":
82
+ case "datetimeTz":
83
+ return this.formatDate(col, format, timezone);
84
+ case "datetimeNoTz":
85
+ return this.formatDate(col, format, void 0, true);
86
+ case "dateOnly":
87
+ case "time":
88
+ return this.formatDate(col, format);
89
+ case "unixTimestamp": {
90
+ 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";
91
+ return this.formatUnixTimestamp(field, format, accuracy, timezone);
92
+ }
93
+ default:
94
+ return col;
95
+ }
96
+ }
97
+ };
98
+ __name(_QueryFormatter, "QueryFormatter");
99
+ let QueryFormatter = _QueryFormatter;
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ QueryFormatter
103
+ });
@@ -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,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, _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 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, _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(_PostgresQueryFormatter, "PostgresQueryFormatter");
60
+ let PostgresQueryFormatter = _PostgresQueryFormatter;
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ PostgresQueryFormatter
64
+ });
@@ -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
+ }
@@ -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 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, preserveLocalTime) {
39
+ const fmt = this.convertFormat(format);
40
+ if (timezone && /^[+-]\d{1,2}:\d{2}$/.test(timezone)) {
41
+ return this.sequelize.fn("strftime", fmt, field, this.getOffsetExpression(timezone));
42
+ }
43
+ if (preserveLocalTime && this.rawTimezone && /^[+-]\d{1,2}:\d{2}$/.test(this.rawTimezone)) {
44
+ return this.sequelize.fn("strftime", fmt, field, this.getOffsetExpression(this.rawTimezone));
45
+ }
46
+ return this.sequelize.fn("strftime", fmt, field);
47
+ }
48
+ formatUnixTimestamp(field, format, accuracy = "second", timezone) {
49
+ const quoted = this.sequelize.getQueryInterface().quoteIdentifiers(field);
50
+ const base = accuracy === "millisecond" ? this.sequelize.literal(`ROUND(${quoted} / 1000)`) : this.sequelize.col(field);
51
+ const args = [base, "unixepoch"];
52
+ if (timezone && /^[+-]\d{1,2}:\d{2}$/.test(timezone)) {
53
+ args.push(this.getOffsetExpression(timezone));
54
+ }
55
+ return this.sequelize.fn("strftime", this.convertFormat(format), this.sequelize.fn("DATETIME", ...args));
56
+ }
57
+ };
58
+ __name(_SQLiteQueryFormatter, "SQLiteQueryFormatter");
59
+ let SQLiteQueryFormatter = _SQLiteQueryFormatter;
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ SQLiteQueryFormatter
63
+ });
@@ -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);