OrientDB:如何检查服务器端函数中的查询结果是否为空?

问题描述 投票:1回答:1

OrientDB允许通过使用OrientDB Studio中的“功能管理”来创建服务器端功能。我正在使用演示数据库,并试图从数据库中查找参数id是否存在(简单情况)。我的问题是如何检查查询结果是否为空?代码和下面的更多详细信息。

我在JS中具有简单的功能:

var queryResult = db.query('select Name from Castles where Id=?',id);
if(queryResult == null){
    response.send(404,"Castle not found", "text/plain", "Error: Castle not found");
}else{
    return queryResult;
}

我的功能管理代码的图像:function body

当我使用参数1(id = 1)运行此函数时,我得到了执行结果:

[{“名称”:“圣天使城堡”}]

但是,当我使用参数id = 1234进行相同操作时,我得到了:

[

]

在第二种情况下,我应该得到响应“错误:未找到城堡”。

我尝试将第二行代码更改为:

if(queryResult == undefined)
if(queryResult["Name"] == null)
if(queryResult.length == 0)
and so on...but the result is the same

我正在使用:Studio版本:3.0.24OrientDB版本:3.0.24

我在文档中找不到如何检查OrientDB 3.0.X中查询结果是否为空

提前感谢。

javascript orientdb orientdb3.0
1个回答
0
投票

看看这是否可以帮助您。逻辑相同,但是在OrientDB-SQL中实现:

    let $queryResult = select Name from Castles where Id = :id;
    if ($queryResult.size() = 0) {
        return "Error: Castle not found";
    }
    return $queryResult;

这应该给您:

[select checkIfCastleExist(1):[{“名称”:“圣安杰洛城堡”}]

select checkIfCastleExist(1234):[{“值”:“错误:未找到城堡”}]

© www.soinside.com 2019 - 2024. All rights reserved.