uni-app HbuilderX3.3.3云函数使用JQL联表查询出错

uni-app HbuilderX3.3.3云函数使用JQL联表查询出错

示例代码:

'use strict';  
exports.main = async (event, context) => {  
    const dbJQL = uniCloud.databaseForJQL({ // 获取JQL database引用,此处需要传入云函数的event和context,必传  
            event,  
            context  
        })  
    const order=dbJQL.collection('food').where("isnew==false").getTemp()  
    const res=dbJQL.collection('show-food',order).get()  
    return res  
};

在JQL编辑器中:

const order=db.collection('food').where("isnew==false").getTemp()  
db.collection('show-food',order).get()

操作步骤:

  • 直接本地运行

预期结果:

  • 查出数据

实际结果:

{"code":"SYNTAX_ERROR","message":"查询语句存在错误,请检查传入的临时表是否正确","systemInfo":Array(0)}

bug描述:

想用JQL的建立临时表来优化查询,在JQL编辑器中可以查到,但到了云函数就不行了。

package.json:

{  
    "name": "food",  
    "version": "1.0.0",  
    "description": "",  
    "main": "index.js",  
    "scripts": {  
        "test": "echo \"Error: no test specified\" && exit 1"  
    },  
    "keywords": [],  
    "extensions": {  
        "uni-cloud-jql": {}  
    },  
    "author": "",  
    "license": "ISC"  
}

更多关于uni-app HbuilderX3.3.3云函数使用JQL联表查询出错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

Bug已确认,感谢反馈

更多关于uni-app HbuilderX3.3.3云函数使用JQL联表查询出错的实战教程也可以访问 https://www.itying.com/category-93-b0.html


3.3.4版本已修复此问题

这个错误是因为在云函数中使用JQL联表查询时,临时表的使用方式不正确。问题出在getTemp()方法返回的是一个临时表定义对象,而不是直接用于查询的临时表。

在云函数中,使用JQL联表查询的正确方式应该是:

'use strict';
exports.main = async (event, context) => {
    const dbJQL = uniCloud.databaseForJQL({
        event,
        context
    })
    
    // 正确的方式:使用getTemp()定义临时表
    const orderTemp = dbJQL.collection('food').where("isnew==false").getTemp()
    
    // 正确的方式:在collection方法中直接使用临时表定义
    const res = await dbJQL.collection('show-food').withTemp({
        order: orderTemp
    }).get()
    
    return res
};

或者更简洁的写法:

'use strict';
exports.main = async (event, context) => {
    const dbJQL = uniCloud.databaseForJQL({
        event,
        context
    })
    
    const res = await dbJQL.collection('show-food')
        .withTemp({
            order: dbJQL.collection('food').where("isnew==false").getTemp()
        })
        .get()
    
    return res
};
回到顶部