skills/vk-basedao-gettabledata/SKILL.md
vk-unicloud框架的vk.baseDao.getTableData方法完整使用指南。Use when working with vk-unicloud-admin framework database queries, especially when: (1) Implementing table data queries with pagination, filtering, and sorting, (2) Using vk-data-table component in admin pages, (3) Writing cloud functions with complex database operations including joins, grouping, and aggregation, (4) Need to understand query parameters, return value structure, and performance optimization.
npx skillsauth add caobingsheng/skills vk-basedao-gettabledataInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
vk.baseDao.getTableData 是 vk-unicloud 框架中用于数据库查询的核心方法,特别适用于万能表格(vk-data-table)组件。它提供了强大的分页、筛选、排序、连表、分组等功能。
// 云函数中
let res = await vk.baseDao.getTableData({
dbName: "表名",
data: {
pageIndex: 1,
pageSize: 20,
formData: {
nickname: "张飞"
},
columns: [
{
key: "nickname",
title: "昵称",
type: "text",
width: 160,
mode: "%%"
}
],
sortRule: [
{ name: "_add_time", type: "desc" }
]
},
whereJson: {
user_id: uid
}
});
{
rows: [], // 数据列表
total: 0, // 总记录数
hasMore: false,// 是否还有下一页
pagination: { // 分页信息
pageIndex: 1,
pageSize: 20
},
getCount: true // 是否执行了count请求
}
vk.baseDao.getTableData 支持多种分页方案,详见 分页方案参考
通过 data.formData 和 data.columns 实现灵活的条件查询,详见 条件查询参考
支持多表关联查询,详见 连表查询参考
支持分组统计和聚合操作,详见 分组查询参考
| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | dbName | String | 是 | 主表表名 | | data | Object | 是 | 查询参数对象 | | whereJson | Object | 否 | 主表强制where条件 | | fieldJson | Object | 否 | 字段显示规则 | | sortArr | Array | 否 | 主表排序规则 | | foreignDB | Array | 否 | 连表规则 | | lastWhereJson | Object | 否 | 连表后的where条件 | | lastSortArr | Array | 否 | 连表后的排序规则 | | addFields | Object | 否 | 添加自定义字段 | | getCount | Boolean | 否 | 是否返回总记录数,默认true | | hasMore | Boolean | 否 | 是否返回精确的hasMore,默认false |
data参数包含前端传递的查询条件和排序规则:
data: {
pageIndex: 1, // 第几页
pageSize: 20, // 每页数量
formData: {}, // 查询条件数据源
columns: [], // 查询条件字段规则
sortRule: [] // 排序规则
}
let res = await vk.baseDao.getTableData({
dbName: "uni-id-users",
data: {
pageIndex: 1,
pageSize: 20
},
whereJson: {
status: 1
}
});
let res = await vk.baseDao.getTableData({
dbName: "订单表",
data: {
pageIndex: 1,
pageSize: 20,
formData: {
status: 1,
createTime: ["2024-01-01", "2024-12-31"]
},
columns: [
{ key: "status", title: "状态", type: "radio", mode: "=" },
{ key: "createTime", title: "创建时间", type: "datetimerange", mode: "[]" }
]
}
});
let res = await vk.baseDao.getTableData({
dbName: "opendb-mall-comments",
data: {
pageIndex: 1,
pageSize: 10
},
foreignDB: [{
dbName: "uni-id-users",
localKey: "user_id",
foreignKey: "_id",
as: "userInfo",
limit: 1
}]
});
getCount: false 避免count请求性能问题详细的使用说明和示例请查看references目录下的文档:
development
Use when working with tdd workflows tdd refactor
testing
Generate failing tests for the TDD red phase to define expected behavior and edge cases.
development
Implement the minimal code needed to make failing tests pass in the TDD green phase.
tools
Use when working with tdd workflows tdd cycle