befly 3.20.11 → 3.21.1

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.
@@ -1,24 +0,0 @@
1
- import { isNonEmptyString } from "../../utils/is.js";
2
- import { builderMethods } from "./builders.js";
3
- import { dataOpsMethods } from "./dataOps.js";
4
- import { executeMethods } from "./execute.js";
5
-
6
- function DbHelper(options) {
7
- this.redis = options.redis;
8
-
9
- if (!isNonEmptyString(options.dbName)) {
10
- throw new Error("DbHelper 初始化失败:dbName 必须为非空字符串", {
11
- cause: null,
12
- code: "validation"
13
- });
14
- }
15
- this.dbName = options.dbName;
16
-
17
- this.sql = options.sql || null;
18
- this.isTransaction = options.isTransaction === true;
19
- this.beflyMode = options.beflyMode === "manual" ? "manual" : "auto";
20
- }
21
-
22
- Object.assign(DbHelper.prototype, builderMethods, executeMethods, dataOpsMethods);
23
-
24
- export { DbHelper };
@@ -1,95 +0,0 @@
1
- import { isNullable, isString } from "../../utils/is.js";
2
- import { canConvertToNumber, snakeCase } from "../../utils/util.js";
3
- import { parseTableRef } from "./validate.js";
4
-
5
- export function quoteIdentMySql(identifier) {
6
- if (!isString(identifier)) {
7
- throw new Error(`quoteIdentifier 需要字符串类型标识符 (identifier: ${String(identifier)})`, {
8
- cause: null,
9
- code: "validation"
10
- });
11
- }
12
-
13
- const trimmed = identifier.trim();
14
- if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(trimmed)) {
15
- throw new Error(`无效的 SQL 标识符: ${trimmed}`, {
16
- cause: null,
17
- code: "validation"
18
- });
19
- }
20
-
21
- return `\`${trimmed}\``;
22
- }
23
-
24
- export function normalizeTableRef(tableRef) {
25
- const parsed = parseTableRef(tableRef);
26
- const schemaPart = parsed.schema ? snakeCase(parsed.schema) : null;
27
- const tablePart = snakeCase(parsed.table);
28
- const aliasPart = parsed.alias ? snakeCase(parsed.alias) : null;
29
- let result = schemaPart ? `${schemaPart}.${tablePart}` : tablePart;
30
- if (aliasPart) {
31
- result = `${result} ${aliasPart}`;
32
- }
33
- return result;
34
- }
35
-
36
- export function getJoinMainQualifier(tableRef) {
37
- const parsed = parseTableRef(tableRef);
38
- if (parsed.alias) {
39
- return snakeCase(parsed.alias);
40
- }
41
- return snakeCase(parsed.table);
42
- }
43
-
44
- export function normalizeSqlMetaNumber(value) {
45
- if (isNullable(value)) {
46
- return 0;
47
- }
48
-
49
- if (typeof value !== "number") {
50
- return 0;
51
- }
52
-
53
- if (!Number.isFinite(value)) {
54
- return 0;
55
- }
56
-
57
- return value;
58
- }
59
-
60
- export function normalizeBigIntValues(arr) {
61
- if (isNullable(arr)) {
62
- return arr;
63
- }
64
-
65
- const convertRecord = (source) => {
66
- const converted = {};
67
-
68
- for (const [key, value] of Object.entries(source)) {
69
- let nextValue = value;
70
-
71
- if (typeof value === "bigint") {
72
- const convertedNumber = canConvertToNumber(value);
73
- if (convertedNumber !== null) {
74
- nextValue = convertedNumber;
75
- } else {
76
- nextValue = String(value);
77
- }
78
- }
79
-
80
- converted[key] = nextValue;
81
- }
82
-
83
- return converted;
84
- };
85
-
86
- if (Array.isArray(arr)) {
87
- return arr.map((item) => convertRecord(item));
88
- }
89
-
90
- if (typeof arr === "object") {
91
- return convertRecord(arr);
92
- }
93
-
94
- return arr;
95
- }