-
Notifications
You must be signed in to change notification settings - Fork 0
GetTableMethod
Michael J. Ryan edited this page May 21, 2015
·
1 revision
The azure-config-util object instance presents a table(name) method that returns a promise, that will resolve to an azure-storage-simple table instance.
This method uses storage(...) to establish an azure-storage-simple connection wrapper.
| Section | Key | JsonValue |
|---|---|---|
| table | mytable | {"storage":"account", "name": "sometablename"} |
- The shown
"name"field in theJsonValueis optional when it matches theKey.
-
storage- specifies the named storage account to use (see storage(...)) -
name- the name of the storage queue to create/use
Will call createTableIfNotExists once under the covers.
// when there's no matching Key, or no "storage" is specified
// under the covers: azureUtil.storage().table('unspecifiedtable');
let unspecTable = await azureUtil.table('unspecifiedtable');
// when there is a matching key
// under the covers: azureUtil.storage('account').blob('somecontainername');
let table = await azureUtil.blob('somecontainer');
// child methods call createTableIfNotExist under the covers (once)
var value = {
'someString': 'value',
'someNumber': 1234,
'someDate': new Date(),
'someObject': {}, //will be JSON.stringified
'someArray': [], //will be JSON.stringified
'falseVal': false,
'trueVal': true
};
await tbl.write('partitionKey','rowKey',value);
var record = await tbl.read('partitionKey','rowKey');
// record is wrapped with parsed values
// original values are buried in the prototype chain
var value2 = result.value; // should deep equal value
//NOTE: wrapped query object mutates
var records = tbl.query() //records starts off as the query object/wrapper
// .select('someString','someNumber') // fields to return (optional)
.where('PartitionKey eq ?', 'partitionKey') // where clause (req)
// .top(5) //limit results, must be under 1000
;
//there is a next method on query, and records that have more
while (records.next) {
// get the next set of results
// if there are more results, will have a .next() function
records = await records.next();
records
.forEach((record)=>{
//do something with unwrapped value
//can access original response with record.__proto__
});
}
//delete an entry from table storage
await tbl.delete('partitionKey','rowKey');