我正在使用Orientjs從nodejs腳本訪問Orientdb數據庫,但服務器端函數不影響數據庫。如何從Orientjs執行Orientdb服務器端函數?
服務器端腳本: 這個Javascript功能addTxt()
取參數author
和text
var db = orient.getGraph();
db.command('sql','insert into Message (author, text) VALUES ("'+author+'", "'+text+'")');
return "1";
查詢:此功能在東方工作室經過測試,下面的查詢工作:
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其他查詢工作。
我在做什麼錯?是否有其他方式來調用服務器端功能?
您可以發佈你的函數的代碼? – wolf4ood
我將它添加到我的文章中。 – Bonzai