How to run an OrientDB function through the sails-orientdb adapter ?
There is an extension to the waterline method with the signature .runFunction('FunctionName', args...) but I cannot get it to work with my use case.
My OrientDB function returns the friends of a given User vertex by it's id :
var db = orient.getGraph();
return db.command("sql", "select expand(unionall(outE('IsFriendsWith').inV(), inE('IsFriendsWith').outV())) from " + id);
My action in the UserController controller calls my orientDB function :
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);
});
}
Am I missing something ?
The console.log(req.param('id')) returns this 33:288786
I get the following logs in the orientdb console :
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
The error tells me that the result needs to be casted to a record ?
I get this result in the OrientDB studio with the id #33:288786 :
[
{
"@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,"
}
]
I am really clueless on what to do. I just started using sails and waterline as well. Thanks in advance !