skills/jql-unicloud/SKILL.md
JQL数据库操作完整使用指南。Use when working with UniCloud JQL database operations, especially when: (1) Using JQL syntax for database queries in clientDB or cloud functions, (2) Implementing complex queries with JQL's simplified syntax (compared to traditional MongoDB), (3) Performing table joins using foreignKey, (4) Using tree queries, grouping, and aggregation, (5) Understanding differences between JQL and vk.baseDao approaches.
npx skillsauth add caobingsheng/skills jql-unicloudInstall 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.
JQL (JavaScript Query Language) 是 UniCloud 提供的一种类 SQL 的数据库查询语法,比传统 MongoDB API 和 SQL 更简单易用。本 skill 提供了 JQL 的完整使用指南,涵盖客户端、云函数、JQL 管理器等所有使用场景。
核心优势:
where('age > 18 && status == 1') 而非复杂的 command 对象与 vk.baseDao 对比:
客户端使用:
const db = uniCloud.databaseForJQL()
云函数使用:
const db = uniCloud.databaseForJQL({
clientInfo: context.CLIENT
})
JQL 数据库管理器:
// 在 HBuilderX 的 JQL 管理器中直接使用 db 变量
db.collection('user').get()
const db = uniCloud.databaseForJQL()
const res = await db.collection('user')
.where('age > 18')
.field('name,age,email')
.orderBy('age desc')
.skip(0)
.limit(20)
.get()
| 特性 | JQL | vk.baseDao | |------|-----|------------| | 使用场景 | 客户端+云函数 | 仅云函数 | | 语法 | 类 SQL 字符串 | JSON 对象 | | 联表查询 | 通过 foreignKey 自动关联 | 需要手动编写 lookup | | 权限校验 | 自动进行 schema 权限校验 | 需要手动编写权限逻辑 | | 学习成本 | 低,类似 SQL | 中,需要了解 MongoDB |
选择建议:
JQL 可以在三种场景中使用,不同场景的权限校验和功能支持有所不同。
setUser 指定用户身份本 skill 采用渐进式披露设计,核心内容在 SKILL.md 中,详细内容在 references/ 目录中。
查看 查询操作 当你需要:
查看 联表查询 当你需要:
查看 高级查询 当你需要:
查看 增删改操作 当你需要:
查看 DB Schema 配置 当你需要:
查看 最佳实践 当你需要:
// 简单查询
const db = uniCloud.databaseForJQL()
const res = await db.collection('user')
.where('age > 18')
.field('name,age')
.orderBy('age desc')
.skip(0)
.limit(20)
.get()
// 临时表联表查询(推荐)
const order = db.collection('order')
.where('quantity > 100')
.getTemp()
const book = db.collection('book')
.where('title == "三国演义"')
.getTemp()
const res = await db.collection(order, book).get()
// 查询部门树
const res = await db.collection('department')
.where('status == 0')
.get({
getTree: {
limitLevel: 10
}
})
// 按日统计订单
const res = await db.collection('order')
.groupBy('dateToString(add(new Date(0),create_time),"%Y-%m-%d","+0800") as date')
.groupField('count(*) as order_count,sum(total_amount) as total_amount')
.get()
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