Retrieving a Single Row

Retrieve a Child Table

To retrieve a single row from the store:

  1. Create a store handle and open it.

  2. Construct a Row node.js object. Each name/value pair in the object must correspond to the primary key and value for the row that you want to retrieve. In this case, the full primary key must be present in the object.

  3. Retrieve the row using Store.get(). This performs the store read operation.

  4. The retrieved row can be obtained using the GetResult.currentRow() method.

For example, in Writing Rows to a Table in the Store we showed a trivial example of storing a table row to the store. The following trivial example shows how to retrieve that row.

var nosqldb = require('nosqldb-oraclejs');

// Create a configuration object
var configuration = new nosqldb.Configuration();
configuration.proxy.startProxy = false;
configuration.proxy.host = 'localhost:7010';
configuration.storeHelperHosts = ['localhost:5000'];
configuration.storeName = 'kvstore';

// Open the store with the specified configuration
var store = nosqldb.createStore(configuration);

store.on('open', function () {
   console.log('Store opened');

   var primaryKey = {item: "Bolts"};

   store.get('myTable', primaryKey,
           function (err, result) {
                if (err)
                    throw err;
                else {
                    console.log("Row retrieved.");
                    console.log(result.currentRow);
                    store.close();
                }
           });
}).on('close', function() {
    console.log('Store closed.');
}).on('error', function(error) {
    console.log(error);
});
store.open(); 

Retrieve a Child Table

In Writing Rows to a Child Table we showed how to populate a child table with data. To retrieve that data, you must specify the primary key used for the parent table row, as well as the primary key for the child table row. For example:

...
// Store handle configuration and open skipped for brevity
...

store.on('open', function () {
   console.log('Store opened');

   var primaryKey = {itemCategory: "Bolts",
                     itemSKU: '1392610'};

   store.get('myInventory.itemDetails', primaryKey,
           function (err, result) {
                if (err)
                    throw err;
                else {
                    console.log("Row retrieved.");
                    console.log(result.currentRow);
                    store.close();
                }
           });
}).on('close', function() {
    console.log('Store closed.');
}).on('error', function(error) {
    console.log(error);
});
store.open(); 

For information on how to iterate over nested tables, see Iterating with Nested Tables.