単一行の取得
ストアから単一行を取得するには、次の手順を実行します。
-
ストア・ハンドルを作成し、開きます。
-
Rownode.jsオブジェクトを構築します。オブジェクトの各名前と値のペアは、取得する行の主キーおよび値に対応している必要があります。この場合、完全な主キーがオブジェクトに存在している必要があります。 -
Store.get()を使用して行を取得します。これにより、ストアの読取り操作が実行されます。 -
取得された行は、
GetResult.currentRow()メソッドを使用して取得できます。
たとえば、「ストアへの行の書込み」では、ストアに表の行を格納する簡単な例を示しました。次の簡単な例では、行の取得方法を示します。
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(); 子表の取得
「子表への行の書込み」では、子表にデータを移入する方法を示しました。そのデータを取得するには、親表の行に使用される主キー、および子表の行の主キーを指定する必要があります。次に例を示します。
...
// 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(); ネスト表を反復する方法の詳細は、「ネストされた表の反復使用」を参照してください。