Friday 21 April 2017

How to load large Oracle table into angular ngTable

I would like to be able to view a rather large legacy oracle database table using Angularjs ngTable. (I am new to using the MEAN stack.) I am using node-oracledb to read from the oracle database, following this example:(https://github.com/oracle/node-oracledb/blob/master/doc/api.md#resultsethandling)

My server side code reads the data from the database in 1000 row chunks. This appears to be working, as far as reading the data, but my angular client does not appear to be getting the results. Using Firefox web console I can see that JSON data eventually appears in the response, but it does not seem to work with my app side angular controller.

What would be the best approach, using angular, to load this data into an ngTable? Do I need to change my server side approach from simply using "res.write()" to using a streaming library? I don't have a good understanding of how the angular client side reads data that is sent in chunks.

My Nodejs server side code that loads data from the oracle table:

var numRows = 1000;  // number of rows to return from each call to getRows()
connection.execute(
  mySqlStr,
  [], // no bind variables
  { resultSet: true }, // return a Result Set.  Default is false
  function(err, result)
  {
    if (err) { . . . }
    fetchRowsFromRS(connection, result.resultSet, numRows);
  });
});

function fetchRowsFromRS(connection, resultSet, numRows)
{
  resultSet.getRows( // get numRows rows
    numRows,
    function (err, rows)
    {
      if (err) {
         . . .      // close the Result Set and release the connection
   } else if (rows.length > 0) {   // got some rows
    res.write( JSON.stringify( rowsToJson( rows, columns ))); // write rows to response for client
    if (rows.length === numRows)  // might be more rows
      fetchRowsFromRS(connection, resultSet, numRows);
    else                          // got fewer rows than requested so must be at end
      . . .                       // close the Result Set and release the connection
  } else {                        // else no rows
      . . .                       // close the Result Set and release the connection
    }
  });
}

The rowsToJson function just converts the data array from each row into JSON using the column names that were in the result.metaData.

On the client side I have something like this:

In my app controller:

vm.myTableParams = new NgTableParams( ... );
...
DataService.loadByQuery( query )
.then( function( data ){
    vm.myTableParams.settings( {dataset: data} );
});

In my app DataService:

function loadData( params ){
    Var d = $q.defer();
    Datasource.load( params )
    .$promise.then(
        function success(data){
            Return d.resolve(data);
        },
        function error(data){
        }
    );
    return d;
}


Function loadByQuery( query ){
    Return loadData( query ).promise;
}

In my app datasource.service:

var load = {
    method: METHODS.GET,
    url: 'api/v1/Datasource/:datasource 

}



via J21042

No comments:

Post a Comment