byteplan-cli 1.3.7 → 1.3.8
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 +1 -1
- package/skills/byteplan-api/scripts/api.js +4 -2
- package/src/api.js +1 -0
- package/src/cli.js +27 -0
package/package.json
CHANGED
|
@@ -627,6 +627,7 @@ export async function queryModels(token, options = {}) {
|
|
|
627
627
|
* @param {Object} params.customQuery - 自定义查询条件
|
|
628
628
|
* @param {string[]} params.groupFields - 分组字段
|
|
629
629
|
* @param {Array} params.functions - 聚合函数
|
|
630
|
+
* @param {Array} params.orderBy - 排序字段 [{field, direction}]
|
|
630
631
|
* @param {number} params.page - 页码(从 0 开始)
|
|
631
632
|
* @param {number} params.pageSize - 每页条数
|
|
632
633
|
* @param {object} options - 可选配置
|
|
@@ -634,11 +635,11 @@ export async function queryModels(token, options = {}) {
|
|
|
634
635
|
* @returns {Promise<{data: Array}>} 返回数据数组,无 total 字段
|
|
635
636
|
*/
|
|
636
637
|
export async function getModelData(token, modelCode, params = {}, options = {}) {
|
|
637
|
-
const { customQuery, groupFields, functions, page = 0, pageSize = 100 } = params;
|
|
638
|
+
const { customQuery, groupFields, functions, orderBy, page = 0, pageSize = 100 } = params;
|
|
638
639
|
const { menuHeaders = {} } = options;
|
|
639
640
|
|
|
640
641
|
// CLI 模式(仅支持简单查询)
|
|
641
|
-
if (useCliMode && !token && !customQuery && !groupFields && !functions) {
|
|
642
|
+
if (useCliMode && !token && !customQuery && !groupFields && !functions && !orderBy) {
|
|
642
643
|
await ensureCliInstalled();
|
|
643
644
|
try {
|
|
644
645
|
const result = await execCli(['data', 'query', modelCode, '-p', String(page), '-s', String(pageSize)]);
|
|
@@ -671,6 +672,7 @@ export async function getModelData(token, modelCode, params = {}, options = {})
|
|
|
671
672
|
groupFields: groupFields || [],
|
|
672
673
|
functions: functions || [],
|
|
673
674
|
customQuery: customQuery || {},
|
|
675
|
+
orderBy: orderBy || [],
|
|
674
676
|
page,
|
|
675
677
|
pageSize,
|
|
676
678
|
};
|
package/src/api.js
CHANGED
|
@@ -339,6 +339,7 @@ export async function getModelData(token, modelCode, params = {}) {
|
|
|
339
339
|
groupFields: params.groupFields || [],
|
|
340
340
|
functions: params.functions || [],
|
|
341
341
|
customQuery: params.customQuery || {},
|
|
342
|
+
orderBy: params.orderBy || [],
|
|
342
343
|
page: params.page || params.pageNum || 0,
|
|
343
344
|
pageSize: params.pageSize || 100,
|
|
344
345
|
}),
|
package/src/cli.js
CHANGED
|
@@ -375,6 +375,7 @@ dataCmd
|
|
|
375
375
|
.option('-q, --query <json>', 'Query condition (JSON format)')
|
|
376
376
|
.option('-g, --group <fields>', 'Group fields (comma separated)')
|
|
377
377
|
.option('-f, --functions <json>', 'Aggregation functions (JSON array)')
|
|
378
|
+
.option('-o, --order <json>', 'Order by fields (JSON array)')
|
|
378
379
|
.addHelpText('after', `
|
|
379
380
|
Examples:
|
|
380
381
|
# Simple query
|
|
@@ -395,6 +396,12 @@ Examples:
|
|
|
395
396
|
# Complete aggregation example
|
|
396
397
|
byteplan data query CBEC_ORDER -g product_id -q '{"type":"condition","field":"order_date","operator":"BETWEEN","value":["2024-01-01","2024-12-31"]}' -f '[{"func":"sum","field":"amount","alias":"total_amount"},{"func":"count","field":"id","alias":"order_count"}]'
|
|
397
398
|
|
|
399
|
+
# With sorting
|
|
400
|
+
byteplan data query CBEC_PRODUCT -o '[{"field":"selling_price","direction":"desc"},{"field":"product_name","direction":"asc"}]'
|
|
401
|
+
|
|
402
|
+
# Combined example with filter and sort
|
|
403
|
+
byteplan data query CBEC_PRODUCT -q '{"type":"condition","field":"category","operator":"=","value":"饮料"}' -o '[{"field":"selling_price","direction":"desc"}]' -s 5
|
|
404
|
+
|
|
398
405
|
Query Syntax:
|
|
399
406
|
|
|
400
407
|
1. Single Condition:
|
|
@@ -439,6 +446,16 @@ Query Syntax:
|
|
|
439
446
|
|
|
440
447
|
Note: When using aggregation functions, -g (group) is usually needed.
|
|
441
448
|
Without grouping, aggregation returns a single summary row.
|
|
449
|
+
|
|
450
|
+
Order By (-o):
|
|
451
|
+
JSON array of sort objects:
|
|
452
|
+
[
|
|
453
|
+
{ "field": "字段名", "direction": "desc" },
|
|
454
|
+
{ "field": "字段名", "direction": "asc" }
|
|
455
|
+
]
|
|
456
|
+
|
|
457
|
+
direction: "asc" (升序) or "desc" (降序)
|
|
458
|
+
Example: -o '[{"field":"created_date","direction":"desc"}]'
|
|
442
459
|
`)
|
|
443
460
|
.action(async (modelCode, options) => {
|
|
444
461
|
try {
|
|
@@ -474,6 +491,16 @@ Query Syntax:
|
|
|
474
491
|
}
|
|
475
492
|
}
|
|
476
493
|
|
|
494
|
+
// 解析排序字段
|
|
495
|
+
if (options.order) {
|
|
496
|
+
try {
|
|
497
|
+
params.orderBy = JSON.parse(options.order);
|
|
498
|
+
} catch (e) {
|
|
499
|
+
printJSON({ error: true, message: 'Invalid JSON order: ' + e.message });
|
|
500
|
+
process.exit(1);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
477
504
|
const result = await getModelData(null, modelCode, params);
|
|
478
505
|
|
|
479
506
|
// result.data 是数据数组
|