gpt4 book ai didi

javascript - 如何从Orientjs执行Orientdb服务器端函数?

转载 作者:行者123 更新时间:2023-12-03 09:44:02 25 4
gpt4 key购买 nike

我正在使用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脚本调用此函数时,它仅返回

[ { '@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 的其他查询有效。

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

最佳答案

您明确返回“1”

返回是对的

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

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

db.commit()

关于javascript - 如何从Orientjs执行Orientdb服务器端函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31093147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com