befly 3.18.17 → 3.18.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/checks/config.js +1 -1
- package/configs/beflyConfig.json +1 -1
- package/lib/dbHelper/builders.js +9 -5
- package/lib/dbHelper/dataOps.js +16 -16
- package/lib/dbHelper/index.js +1 -1
- package/lib/dbHelper/transaction.js +1 -1
- package/lib/sqlBuilder/batch.js +4 -2
- package/package.json +2 -2
- package/plugins/mysql.js +1 -1
- package/scripts/syncDb/context.js +1 -1
package/checks/config.js
CHANGED
package/configs/beflyConfig.json
CHANGED
package/lib/dbHelper/builders.js
CHANGED
|
@@ -355,8 +355,8 @@ export function processJoinOn(on) {
|
|
|
355
355
|
return result;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
export function addDefaultStateFilter(where = {}, table, hasJoins = false,
|
|
359
|
-
if (
|
|
358
|
+
export function addDefaultStateFilter(where = {}, table, hasJoins = false, beflyMode = 1) {
|
|
359
|
+
if (beflyMode === 0) {
|
|
360
360
|
return where;
|
|
361
361
|
}
|
|
362
362
|
|
|
@@ -494,8 +494,10 @@ export function buildInsertRow(options) {
|
|
|
494
494
|
result["id"] = options.id;
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
-
|
|
498
|
-
|
|
497
|
+
if (options.beflyMode !== 0) {
|
|
498
|
+
result["created_at"] = options.now;
|
|
499
|
+
result["updated_at"] = options.now;
|
|
500
|
+
}
|
|
499
501
|
result["state"] = 1;
|
|
500
502
|
return result;
|
|
501
503
|
}
|
|
@@ -508,7 +510,9 @@ export function buildUpdateRow(options) {
|
|
|
508
510
|
for (const [key, value] of Object.entries(userData)) {
|
|
509
511
|
result[key] = value;
|
|
510
512
|
}
|
|
511
|
-
|
|
513
|
+
if (options.beflyMode !== 0) {
|
|
514
|
+
result["updated_at"] = options.now;
|
|
515
|
+
}
|
|
512
516
|
return result;
|
|
513
517
|
}
|
|
514
518
|
|
package/lib/dbHelper/dataOps.js
CHANGED
|
@@ -13,7 +13,7 @@ export const dataOpsMethods = {
|
|
|
13
13
|
const { table, where, joins, tableQualifier } = await this.prepareQueryOptions(options, "getCount.options");
|
|
14
14
|
const hasJoins = Array.isArray(joins) && joins.length > 0;
|
|
15
15
|
|
|
16
|
-
const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.
|
|
16
|
+
const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.beflyMode);
|
|
17
17
|
const result = await this.fetchCount({ table: table, joins: joins }, whereFiltered, "COUNT(*) as count");
|
|
18
18
|
|
|
19
19
|
return {
|
|
@@ -26,7 +26,7 @@ export const dataOpsMethods = {
|
|
|
26
26
|
const { table, fields, where, joins, tableQualifier } = await this.prepareQueryOptions(options, "getOne.options");
|
|
27
27
|
const hasJoins = Array.isArray(joins) && joins.length > 0;
|
|
28
28
|
|
|
29
|
-
const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.
|
|
29
|
+
const whereFiltered = addDefaultStateFilter(where, tableQualifier, hasJoins, this.beflyMode);
|
|
30
30
|
const builder = this.createSqlBuilder().select(fields).from(table).where(whereFiltered);
|
|
31
31
|
this.applyJoins(builder, joins);
|
|
32
32
|
|
|
@@ -50,7 +50,7 @@ export const dataOpsMethods = {
|
|
|
50
50
|
validatePageLimitRange(prepared, options.table);
|
|
51
51
|
|
|
52
52
|
const hasJoins = Array.isArray(prepared.joins) && prepared.joins.length > 0;
|
|
53
|
-
const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.
|
|
53
|
+
const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.beflyMode);
|
|
54
54
|
const countResult = await this.fetchCount(prepared, whereFiltered, "COUNT(*) as total");
|
|
55
55
|
const total = countResult.total;
|
|
56
56
|
|
|
@@ -102,7 +102,7 @@ export const dataOpsMethods = {
|
|
|
102
102
|
const prepared = await this.prepareQueryOptions(prepareOptions, "getAll.options");
|
|
103
103
|
|
|
104
104
|
const hasJoins = Array.isArray(prepared.joins) && prepared.joins.length > 0;
|
|
105
|
-
const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.
|
|
105
|
+
const whereFiltered = addDefaultStateFilter(prepared.where, prepared.tableQualifier, hasJoins, this.beflyMode);
|
|
106
106
|
const countResult = await this.fetchCount(prepared, whereFiltered, "COUNT(*) as total");
|
|
107
107
|
const total = countResult.total;
|
|
108
108
|
|
|
@@ -150,7 +150,7 @@ export const dataOpsMethods = {
|
|
|
150
150
|
validateNoJoinReadOptions(options, "exists", "exists 不支持 joins(请使用显式 query 或拆分查询)");
|
|
151
151
|
const snakeTable = snakeCase(options.table);
|
|
152
152
|
const snakeWhere = whereKeysToSnake(clearDeep(options.where || {}));
|
|
153
|
-
const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.
|
|
153
|
+
const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
|
|
154
154
|
|
|
155
155
|
const builder = this.createSqlBuilder().selectRaw("COUNT(1) as cnt").from(snakeTable).where(whereFiltered).limit(1);
|
|
156
156
|
const { sql, params } = builder.toSelectSql();
|
|
@@ -194,7 +194,7 @@ export const dataOpsMethods = {
|
|
|
194
194
|
|
|
195
195
|
let processed;
|
|
196
196
|
if (this.idMode === "autoId") {
|
|
197
|
-
processed = buildInsertRow({ idMode: "autoId", data: data, now: now });
|
|
197
|
+
processed = buildInsertRow({ idMode: "autoId", data: data, now: now, beflyMode: this.beflyMode });
|
|
198
198
|
} else {
|
|
199
199
|
let id;
|
|
200
200
|
try {
|
|
@@ -208,7 +208,7 @@ export const dataOpsMethods = {
|
|
|
208
208
|
table: table
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
|
-
processed = buildInsertRow({ idMode: "timeId", data: data, id: id, now: now });
|
|
211
|
+
processed = buildInsertRow({ idMode: "timeId", data: data, id: id, now: now, beflyMode: this.beflyMode });
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
assertNoUndefinedInRecord(processed, `insData 插入数据 (table: ${snakeTable})`);
|
|
@@ -253,7 +253,7 @@ export const dataOpsMethods = {
|
|
|
253
253
|
let processedList;
|
|
254
254
|
if (this.idMode === "autoId") {
|
|
255
255
|
processedList = dataList.map((data) => {
|
|
256
|
-
return buildInsertRow({ idMode: "autoId", data: data, now: now });
|
|
256
|
+
return buildInsertRow({ idMode: "autoId", data: data, now: now, beflyMode: this.beflyMode });
|
|
257
257
|
});
|
|
258
258
|
} else {
|
|
259
259
|
const nextIds = [];
|
|
@@ -264,7 +264,7 @@ export const dataOpsMethods = {
|
|
|
264
264
|
processedList = dataList.map((data, index) => {
|
|
265
265
|
const id = nextIds[index];
|
|
266
266
|
validateGeneratedBatchId(id, snakeTable, index);
|
|
267
|
-
return buildInsertRow({ idMode: "timeId", data: data, id: id, now: now });
|
|
267
|
+
return buildInsertRow({ idMode: "timeId", data: data, id: id, now: now, beflyMode: this.beflyMode });
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
|
|
@@ -383,10 +383,10 @@ export const dataOpsMethods = {
|
|
|
383
383
|
rows: processedList,
|
|
384
384
|
fields: fields,
|
|
385
385
|
quoteIdent: quoteIdentMySql,
|
|
386
|
-
updatedAtField: "updated_at",
|
|
387
|
-
updatedAtValue: now,
|
|
386
|
+
updatedAtField: this.beflyMode === 1 ? "updated_at" : "",
|
|
387
|
+
updatedAtValue: this.beflyMode === 1 ? now : null,
|
|
388
388
|
stateField: "state",
|
|
389
|
-
stateGtZero:
|
|
389
|
+
stateGtZero: this.beflyMode === 1
|
|
390
390
|
});
|
|
391
391
|
|
|
392
392
|
const executeRes = await this.execute(query.sql, query.params);
|
|
@@ -404,8 +404,8 @@ export const dataOpsMethods = {
|
|
|
404
404
|
const snakeTable = snakeCase(table);
|
|
405
405
|
const snakeWhere = whereKeysToSnake(clearDeep(where));
|
|
406
406
|
|
|
407
|
-
const processed = buildUpdateRow({ data: data, now: Date.now(), allowState: true });
|
|
408
|
-
const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.
|
|
407
|
+
const processed = buildUpdateRow({ data: data, now: Date.now(), allowState: true, beflyMode: this.beflyMode });
|
|
408
|
+
const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
|
|
409
409
|
const builder = this.createSqlBuilder().where(whereFiltered);
|
|
410
410
|
const { sql, params } = builder.toUpdateSql(snakeTable, processed);
|
|
411
411
|
|
|
@@ -423,7 +423,7 @@ export const dataOpsMethods = {
|
|
|
423
423
|
|
|
424
424
|
return await this.updData({
|
|
425
425
|
table: table,
|
|
426
|
-
data: { state: 0, deleted_at: Date.now() },
|
|
426
|
+
data: this.beflyMode === 1 ? { state: 0, deleted_at: Date.now() } : { state: 0 },
|
|
427
427
|
where: where
|
|
428
428
|
});
|
|
429
429
|
},
|
|
@@ -478,7 +478,7 @@ export const dataOpsMethods = {
|
|
|
478
478
|
const snakeField = snakeCase(field);
|
|
479
479
|
|
|
480
480
|
const snakeWhere = whereKeysToSnake(clearDeep(where));
|
|
481
|
-
const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.
|
|
481
|
+
const whereFiltered = addDefaultStateFilter(snakeWhere, snakeTable, false, this.beflyMode);
|
|
482
482
|
const builder = this.createSqlBuilder().where(whereFiltered);
|
|
483
483
|
const { sql: whereClause, params: whereParams } = builder.getWhereConditions();
|
|
484
484
|
|
package/lib/dbHelper/index.js
CHANGED
|
@@ -19,7 +19,7 @@ function DbHelper(options) {
|
|
|
19
19
|
this.sql = options.sql || null;
|
|
20
20
|
this.isTransaction = Boolean(options.sql);
|
|
21
21
|
this.idMode = options.idMode === "autoId" ? "autoId" : "timeId";
|
|
22
|
-
this.
|
|
22
|
+
this.beflyMode = options.beflyMode === 0 ? 0 : 1;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
Object.assign(DbHelper.prototype, builderMethods, executeMethods, dataOpsMethods, transactionMethods);
|
|
@@ -26,7 +26,7 @@ export const transactionMethods = {
|
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
28
|
return await sql.begin(async (tx) => {
|
|
29
|
-
const trans = new this.constructor({ redis: this.redis, dbName: this.dbName, sql: tx, idMode: this.idMode,
|
|
29
|
+
const trans = new this.constructor({ redis: this.redis, dbName: this.dbName, sql: tx, idMode: this.idMode, beflyMode: this.beflyMode });
|
|
30
30
|
const result = await callback(trans);
|
|
31
31
|
if (isBeflyResponse(result) && result.code !== 0) {
|
|
32
32
|
throw new TransAbortError(result);
|
package/lib/sqlBuilder/batch.js
CHANGED
|
@@ -97,8 +97,10 @@ export function toUpdateCaseByIdSql(options) {
|
|
|
97
97
|
setSqlList.push(`${quotedField} = CASE ${quotedId} ${whenList.join(" ")} ELSE ${quotedField} END`);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
if (isNonEmptyString(options.updatedAtField)) {
|
|
101
|
+
setSqlList.push(`${options.quoteIdent(options.updatedAtField)} = ?`);
|
|
102
|
+
args.push(options.updatedAtValue);
|
|
103
|
+
}
|
|
102
104
|
|
|
103
105
|
for (const id of ids) {
|
|
104
106
|
args.push(id);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.18.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.18.18",
|
|
4
|
+
"gitHead": "f6704475f6922c4f758a93a97872363bbaeaa940",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
package/plugins/mysql.js
CHANGED
|
@@ -68,7 +68,7 @@ export async function prepareSyncDbBaseContext(mysqlConfig) {
|
|
|
68
68
|
dbName: mysqlConfig.database,
|
|
69
69
|
sql: Connect.getMysql(),
|
|
70
70
|
idMode: mysqlConfig.idMode,
|
|
71
|
-
|
|
71
|
+
beflyMode: mysqlConfig.beflyMode
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
const dbColumns = await querySyncDbColumns(mysql);
|