如何从 Orientjs 执行 Orientdb 服务器端功能?

How to execute Orientdb server side function from Orientjs?

我正在使用 Orientjs 从 nodejs 脚本访问 Orientdb 数据库,但服务器端功能不会影响数据库。

服务器端脚本: 这个 Javascript 函数 addTxt() 接受参数 authortext

var db = orient.getGraph();
db.command('sql','insert into Message (author, text) VALUES ("'+author+'", "'+text+'")');
return "1";

查询: 此函数已在 Orient Studio 中测试,以下查询有效:

SELECT addTxt("Testuser","foo")

Nodejs/Orientjs: 当使用 Orientjs 从 nodejs 脚本调用此函数时,它仅 returns

[ { '@type': 'd', addTxt: '1', '@rid': { cluster: -2, position: 1 } } ]

并且数据库保持不变。

我试过:

//some code

var OrientDB = require('orientjs');    
var server = OrientDB({
    host: 'localhost',
    port: 2424,
});

var db = server.use({
    name: 'database',
    username: 'admin',
    password: 'pass'

db.query('SELECT addTxt(:arg1, :arg2)', {
    params: {arg1:"Testuser",arg2:"foo"}
}).then(function (response){
    console.log(response);
});

来自 Orientjs 的其他查询有效。

我做错了什么?还有其他方法可以调用服务器端函数吗?

你显式returns“1”

returns

是对的
[ { '@type': 'd', addTxt: '1', '@rid': { cluster: -2, position: 1 } } ]

尝试在你的函数中直接显式提交

db.commit()