我的目标是从Oracle数据库中检索数据并通过设置OData端点来公开数据。我按照链接 - http://jaydata.org/blog/how-to-set-up-a-nodejs-odata-endpoint-with-odata-server中的说明设置OData端点。我可以成功设置它。我能够通过在我的机器中安装Node-Oracledb驱动程序,按照link-github.com/oracle/node-oracledb/blob/master/INSTALL.md中的说明从我的本地oracle数据库中检索数据。现在我想初始化虚拟实体( Todo)我使用Oracle数据创建,以便外部系统可以访问OData端点。我的代码如下。
require('odata-server');
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');
$data.Entity.extend("Todo", {
Id: { type: "id", key: true, computed: true },
Task: { type: String, required: true, maxLength: 200 },
DueDate: { type: Date },
Completed: { type: Boolean }
});
$data.EntityContext.extend("TodoDatabase", {
Todos: { type: $data.EntitySet, elementType: Todo }
});
console.log('passed0');
var context = new TodoDatabase({provider: 'oracle', databaseName: 'TodoDatabase'});
console.log('passed1');
context.onReady(function() {
var todo1 = new Todo({ Name: 'MyFirstTask'});
context.Todos.add(todo1);
console.log('passed2');
context.saveChanges(function(result) {
//check the content of WebSQL DB
console.log(todo1);
console.log('passed3');
});
});
oracledb.getConnection(
{
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString
},
function(err, connection)
{
if (err) {
console.error(err.message);
return;
}
connection.execute(
"SELECT department_id, department_name "
+ "FROM hr.departments "
+ "WHERE department_id = :did",
[120],
function(err, result)
{
if (err) {
console.error(err.message);
doRelease(connection);
return;
}
console.log(result.metaData);
console.log(result.rows);
//doRelease(connection);
});
});
$data.createODataServer(TodoDatabase, '/todo', 52999, 'localhost');
当我尝试通过在浏览器中运行网址http://localhost:52999/todo/Todos来访问“Todos”集合时,我收到以下错误。请帮助
TypeError: Cannot read property 'providerConfiguration' of undefined
at JSObjectAdapter.$data.Class.define.processRequest (C:\Program Files\nodejs\node_modules\npm\node_modules\jaydata\lib\JayService\JSObjectAdapter.js:79:147)
at JSObjectAdapter.$data.Class.define.handleRequest (C:\Program Files\nodejs\node_modules\npm\node_modules\jaydata\lib\JayService\JSObjectAdapter.js:170:26)
at C:\Program Files\nodejs\node_modules\npm\node_modules\jaydata\lib\JayService\JayService.js:61:21
at C:\Program Files\nodejs\node_modules\npm\node_modules\odata-server\index.js:121:36
at Domain.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\odata-server\index.js:81:13)
at Domain.run (domain.js:197:16)
at errorFn (C:\Program Files\nodejs\node_modules\npm\node_modules\odata-server\index.js:80:14)
at C:\Program Files\nodejs\node_modules\npm\node_modules\odata-server\index.js:118:29
at C:\Program Files\nodejs\node_modules\npm\node_modules\jaydata\lib\JayService\OData\Helpers.js:144:17
at simpleBodyFn (C:\Program Files\nodejs\node_modules\npm\node_modules\odata-server\index.js:63:56)