提交 f652002a 编写于 作者: 雪洛's avatar 雪洛

feat: 新增合并查询请求示例

上级 054ebc58
......@@ -17,6 +17,7 @@ describe('unicloud-database', () => {
await page.callMethod('dbGetWithCommand')
await page.callMethod('dbUpdate')
await page.callMethod('dbRemove')
await page.callMethod('dbMultiSend')
const {
addId,
......@@ -26,6 +27,7 @@ describe('unicloud-database', () => {
getData,
getWithCommandData,
removeDeleted,
multiSendSuccessCount,
} = await page.data()
expect(addId !== '').toBe(true)
......@@ -35,6 +37,7 @@ describe('unicloud-database', () => {
expect(getWithCommandData.length).toBe(1)
expect(updateUpdated).toBe(3)
expect(removeDeleted).toBe(3)
expect(multiSendSuccessCount).toBe(2)
})
......
......@@ -14,6 +14,7 @@
<button type="primary" @click="dbRemove">删除数据</button>
<button type="primary" @click="dbLookupInit">初始化联表查询数据</button>
<button type="primary" @click="dbLookup">联表查询</button>
<button type="primary" @click="dbMultiSend">合并查询查询</button>
</view>
</view>
</view>
......@@ -35,6 +36,7 @@
getWithCommandData: [] as Array<UTSJSONObject>,
removeDeleted: 0,
lookupData: [] as Array<UTSJSONObject>,
multiSendSuccessCount: 0,
isUniTest: false
}
},
......@@ -278,6 +280,39 @@
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbMultiSend() {
const db = uniCloud.databaseForJQL()
const temp1 = db.collection('type')
.where(
'tag == "default-tag"'
).getTemp()
const temp2 = db.collection('type')
.where(
'tag == "default-tag"'
).getTemp()
db.multiSend(temp1, temp2)
.then<void>(res => {
uni.hideLoading()
let successCount = 0
for (let i = 0; i < res.dataList.length; i++) {
const item = res.dataList[i]
if(item.errCode == 0) {
console.log(`第${i}个请求查询到${item.data!.length}条数据`)
successCount++
} else {
console.error(`第${i}个请求查询失败,错误信息:${item.data!.length}`)
}
}
this.multiSendSuccessCount = successCount
this.notify(`合并查询成功,成功查询的语句条数为:${successCount}`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
console.error(err)
this.notify(error.errMsg, '错误')
})
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册