Table object
The feature described in this topic is available only in preview. To use this feature and other new Windows Azure capabilities, sign up for the free preview.
Provides functionality for working with specific tables.
This object contains the following members:
Methods
| Syntax | Returns | Description | ||
|---|---|---|---|---|
|
del |
|
|
||
|
|
undefined |
Deletes the specified itemID, where itemID can be either the item a row with the specified ID. |
||
|
insert |
|
|
||
|
|
undefined |
Inserts the specified item into the specified tableName. |
||
|
orderBy |
|
|
||
|
|
Returns a Query object instance where the query is ordered by the supplied column name arguments, in ascending order. |
|||
|
orderByDescending |
|
|
||
|
|
Returns a Query object instance where the query is ordered by the supplied column name arguments, in descending order. |
|||
|
read |
|
|
||
|
|
undefined |
Reads all data from the table and invokes the success handler specified on the options parameter passing in an array of results.
|
||
|
select |
|
|
||
|
|
Returns a Query object instance with the requested string projection applied. |
|||
|
|
Returns a Query object instance with the requested function projection applied. |
|||
|
skip |
|
|
||
|
|
Returns a Query object instance that skips the first recordCount number of records. |
|||
|
take |
|
|
||
|
|
Returns a Query object instance that returns the recordCount number of records. |
|||
|
where |
|
|
||
|
|
Returns a Query object instance that is filtered based on the property values of the supplied JSON object. |
|||
|
|
Returns a Query object instance that is filtered based on the supplied function. |
|||
|
update |
|
|
||
|
|
undefined |
Updates the specified item in into the specified tableName. |
||
insert, update, and del methods accept an options object, which can have success or error handlers defined.
Query methods (orderBy, orderByDescending, select, skip, take and where all return a Query object. This object exposes these same methods, which enables you to compose queries as a series of method calls.
The following script calls the where method to filter the returned rows by the supplied object values. When at least one record is returned, it is assumed that the user has the necessary permission to submit an order and the insert is executed; otherwise an error is returned.
function insert(item, user, request) { var permissionsTable = tables.getTable('permissions'); permissionsTable.where({ userId: user.userId, permission: 'submit order' }).read({ success: function(results) { if (results.length > 0) { // Permission record was found. Continue normal execution. request.execute(); } else { console.log('User %s attempted to submit an order without permissions.', user.userId); request.respond(statusCodes.FORBIDDEN, 'You do not have permission to submit orders.'); } } }); }
The following function, from a scheduled job, executes Transact-SQL that returns duplicate rows and then uses the del method to remove the duplicates.
function cleanup_channels() {
var sql = "SELECT MAX(Id) as Id, Uri FROM Channel " +
"GROUP BY Uri HAVING COUNT(*) > 1";
var channelTable = tables.getTable('Channel');
mssql.query(sql, {
success: function(results) {
if (results.length > 0) {
for (var i = 0; i < results.length; i++) {
channelTable.del(results[i].Id);
console.log('Deleted duplicate channel:' +
results[i].Uri);
}
} else {
console.log('No duplicate rows found.');
}
}
});
}
Important