2015-06-27 36 views
0

我正在使用Orientjs從nodejs腳本訪問Orientdb數據庫,但服務器端函數不影響數據庫。如何從Orientjs執行Orientdb服務器端函數?

服務器端腳本: 這個Javascript功能addTxt()取參數authortext

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其他查詢工作。

我在做什麼錯?是否有其他方式來調用服務器端功能?

+0

您可以發佈你的函數的代碼? – wolf4ood

+0

我將它添加到我的文章中。 – Bonzai

回答

1

你明確的回報 「1」

這是正確的返回

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

嘗試在函數直接明確的承諾

db.commit()

+0

謝謝!它正在使用db.commit()。返回「1」僅用於調試目的。 – Bonzai

+0

我遇到了同樣的問題。如果使用其他函數內的函數編輯數據,則可能需要提交不同的級別。太糟糕了,沒有更好的記錄。 –

相關問題