diff --git a/pages/API/unicloud-database/unicloud-database.test.js b/pages/API/unicloud-database/unicloud-database.test.js index 80855554214ae8f9c53506ab411ba8ddcbe35334..cec19a63b982c7d2461344fa0bb682f917934fb4 100644 --- a/pages/API/unicloud-database/unicloud-database.test.js +++ b/pages/API/unicloud-database/unicloud-database.test.js @@ -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) }) diff --git a/pages/API/unicloud-database/unicloud-database.uvue b/pages/API/unicloud-database/unicloud-database.uvue index aeb650c1553e4a9dc95de3202d4ca9f811cfecfc..36cb30f452d0f61bbcd12299533ed0dc2c985a10 100644 --- a/pages/API/unicloud-database/unicloud-database.uvue +++ b/pages/API/unicloud-database/unicloud-database.uvue @@ -14,6 +14,7 @@ + @@ -35,6 +36,7 @@ getWithCommandData: [] as Array, removeDeleted: 0, lookupData: [] as Array, + 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(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((err : any | null) => { + uni.hideLoading() + const error = err as UniCloudError + console.error(err) + this.notify(error.errMsg, '错误') + }) } } }