befly 2.0.9 → 2.0.10
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/package.json +2 -2
- package/plugins/db.js +2 -2
- package/utils/curd.js +24 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Buma - 为 Bun 专属打造的 API 接口框架核心引擎",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"README.md",
|
|
52
52
|
"vitest.config.js"
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "e87ddebec60d7dcde96510b2177ec23719972f54"
|
|
55
55
|
}
|
package/plugins/db.js
CHANGED
|
@@ -216,7 +216,7 @@ export default {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
const { sql, params } = builder.toSelectSql();
|
|
219
|
-
const
|
|
219
|
+
const rows = await this.#executeWithConn(sql, params, conn);
|
|
220
220
|
|
|
221
221
|
// 获取总数(如果需要分页)
|
|
222
222
|
let total = 0;
|
|
@@ -241,7 +241,7 @@ export default {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
return {
|
|
244
|
-
|
|
244
|
+
rows: Array.isArray(rows) ? rows : [],
|
|
245
245
|
total,
|
|
246
246
|
page: numPage,
|
|
247
247
|
pageSize: numPageSize
|
package/utils/curd.js
CHANGED
|
@@ -192,43 +192,31 @@ export class SqlBuilder {
|
|
|
192
192
|
return this;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
orderBy(
|
|
196
|
-
if (Array.isArray(
|
|
197
|
-
|
|
198
|
-
if (typeof item === 'string' && item.includes('#')) {
|
|
199
|
-
const [fieldName, dir] = item.split('#');
|
|
200
|
-
const cleanDir = (dir || 'ASC').trim().toUpperCase();
|
|
201
|
-
if (!['ASC', 'DESC'].includes(cleanDir)) {
|
|
202
|
-
throw new Error('ORDER BY direction must be ASC or DESC');
|
|
203
|
-
}
|
|
204
|
-
this._orderBy.push(`${fieldName.trim()} ${cleanDir}`);
|
|
205
|
-
} else if (Array.isArray(item) && item.length >= 1) {
|
|
206
|
-
const [fieldName, dir] = item;
|
|
207
|
-
const cleanDir = (dir || 'ASC').toUpperCase();
|
|
208
|
-
if (!['ASC', 'DESC'].includes(cleanDir)) {
|
|
209
|
-
throw new Error('ORDER BY direction must be ASC or DESC');
|
|
210
|
-
}
|
|
211
|
-
this._orderBy.push(`${fieldName} ${cleanDir}`);
|
|
212
|
-
} else if (typeof item === 'string') {
|
|
213
|
-
this._orderBy.push(`${item} ASC`);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
} else if (typeof field === 'string') {
|
|
217
|
-
if (field.includes('#')) {
|
|
218
|
-
const [fieldName, dir] = field.split('#');
|
|
219
|
-
const cleanDir = (dir || 'ASC').trim().toUpperCase();
|
|
220
|
-
if (!['ASC', 'DESC'].includes(cleanDir)) {
|
|
221
|
-
throw new Error('ORDER BY direction must be ASC or DESC');
|
|
222
|
-
}
|
|
223
|
-
this._orderBy.push(`${fieldName.trim()} ${cleanDir}`);
|
|
224
|
-
} else {
|
|
225
|
-
const cleanDir = direction.toUpperCase();
|
|
226
|
-
if (!['ASC', 'DESC'].includes(cleanDir)) {
|
|
227
|
-
throw new Error('ORDER BY direction must be ASC or DESC');
|
|
228
|
-
}
|
|
229
|
-
this._orderBy.push(`${field} ${cleanDir}`);
|
|
230
|
-
}
|
|
195
|
+
orderBy(fields) {
|
|
196
|
+
if (!Array.isArray(fields)) {
|
|
197
|
+
throw new Error('orderBy must be an array of strings in "field#direction" format');
|
|
231
198
|
}
|
|
199
|
+
|
|
200
|
+
fields.forEach((item) => {
|
|
201
|
+
if (typeof item !== 'string' || !item.includes('#')) {
|
|
202
|
+
throw new Error('orderBy field must be a string in "field#direction" format (e.g., "name#ASC", "id#DESC")');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const [fieldName, direction] = item.split('#');
|
|
206
|
+
const cleanField = fieldName.trim();
|
|
207
|
+
const cleanDir = direction.trim().toUpperCase();
|
|
208
|
+
|
|
209
|
+
if (!cleanField) {
|
|
210
|
+
throw new Error('Field name cannot be empty in orderBy');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!['ASC', 'DESC'].includes(cleanDir)) {
|
|
214
|
+
throw new Error('ORDER BY direction must be ASC or DESC');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this._orderBy.push(`${cleanField} ${cleanDir}`);
|
|
218
|
+
});
|
|
219
|
+
|
|
232
220
|
return this;
|
|
233
221
|
}
|
|
234
222
|
|