1

My objective is to retrieve the data from Oracle database and expose the data by setting a OData endpoint.I followed instructions in link-http://jaydata.org/blog/how-to-set-up-a-nodejs-odata-endpoint-with-odata-server to setup OData end point.I can successfully set this up.I am able to retrieve data from my local oracle database by installing Node-Oracledb driver in my machine by following instructions in link- github.com/oracle/node-oracledb/blob/master/INSTALL.md .Now I want to initialize the dummy entity(Todo) I created with Oracle data so that external system can access with OData endpoint.My code is as below.

    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');

I am receiving below error when I try to access 'Todos' collection by running URL-http://localhost:52999/todo/Todos in the browser.Please help

    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)
Trott
  • 66,479
  • 23
  • 173
  • 212
Suneel
  • 131
  • 5

0 Answers0