0

如何通过sails-orientdb 适配器运行OrientDB 函数?

带有签名.runFunction('FunctionName', args...)的水线方法有一个扩展, 但我无法让它与我的用例一起使用。

我的 OrientDB 函数通过它的 id 返回给定用户顶点的朋友:

var db = orient.getGraph(); 

return db.command("sql", "select expand(unionall(outE('IsFriendsWith').inV(), inE('IsFriendsWith').outV())) from " + id);

我在 UserController 控制器中的操作调用了我的 orientDB 函数:

findFriends: function (req, res, next) {
    console.log(req.param('id'));
    User.runFunction('findFriends', '#' + req.param('id')).from('OUser').limit(20).one()
        .then(function (result) {
                res.json(result);
    });
}

我错过了什么吗?

console.log(req.param('id')) 返回这个 33:288786

我在 orientdb 控制台中得到以下日志:

    Cannot serialize record: #-2:0{findFriends:[3]} v0 [ONetworkProtocolBinary]{db=database} Error on unmarshalling record #-2:0 (java.lang.ClassCastException: com.tinkerpop.blueprints.impls.orient.OrientVertex cannot be cast to com.orientechnologies.orient.core.record.ORecord)
java.lang.ClassCastException: com.tinkerpop.blueprints.impls.orient.OrientVertex cannot be cast to com.orientechnologies.orient.core.record.ORecord
    at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract.fieldTypeToString(ORecordSerializerStringAbstract.java:197)
    at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerCSVAbstract.embeddedCollectionToStream(ORecordSerializerCSVAbstract.java:843)
    at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerCSVAbstract.fieldToStream(ORecordSerializerCSVAbstract.java:534)
    at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV.toString(ORecordSerializerSchemaAware2CSV.java:506)
    at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract.toStream(ORecordSerializerStringAbstract.java:688)
    at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV.toStream(ORecordSerializerSchemaAware2CSV.java:268)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:2102)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:714)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.getRecordBytes(OBinaryNetworkProtocolAbstract.java:417)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.writeRecord(OBinaryNetworkProtocolAbstract.java:432)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.writeIdentifiable(OBinaryNetworkProtocolAbstract.java:136)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1226)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:386)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:217)
    at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:69

错误告诉我需要将结果转换为记录?

我在 ID 为 #33:288786 的 OrientDB 工作室中得到了这个结果:

    [
    {
        "@type": "d",
        "@rid": "#33:288787",
        "@version": 16,
        "@class": "User",
        "gender": false,
        "mail": "1",
        "no": "1",
        "moto": "1",
        "rel": "1",
        "ori": "1",
        "pass": "1",
        "birthDate": null,
        "online": false,
        "name": "1",
        "in_IsFriendsWith": [
            "#23:4"
        ],
        "@fieldTypes": "in_IsFriendsWith=g,"
    }
]

我真的不知道该怎么做。我也刚开始使用帆和水线。提前致谢 !

4

0 回答 0