0 out of 1 rated this helpful - Rate this topic

Table object

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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

Table.del(itemOrId, options)

undefined

Deletes the specified itemID, where itemID can be either the item a row with the specified ID.

insert

Table.insert(item, options)

undefined

Inserts the specified item into the specified tableName.

orderBy

Table.orderBy(arg1, arg2, …)

Query object

Returns a Query object instance where the query is ordered by the supplied column name arguments, in ascending order.

orderByDescending

Table.orderByDescending(arg1, arg2, …)

Query object

Returns a Query object instance where the query is ordered by the supplied column name arguments, in descending order.

read

Table.read(options)

undefined

Reads all data from the table and invokes the success handler specified on the options parameter passing in an array of results.

ImportantImportant
You should not call the read method on tables of unbounded size.

select

Table.select(string)

Query object

Returns a Query object instance with the requested string projection applied.

Table.select(function)

Query object

Returns a Query object instance with the requested function projection applied.

skip

Table.skip(recordCount)

Query object

Returns a Query object instance that skips the first recordCount number of records.

take

Table.take(recordCount)

Query object

Returns a Query object instance that returns the recordCount number of records.

where

Table.where(object)

Query object

Returns a Query object instance that is filtered based on the property values of the supplied JSON object.

Table.where(function)

Query object

Returns a Query object instance that is filtered based on the supplied function.

update

Table.update(item, options)

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.');
            }
        }
    });
}

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.
facebook page visit twitter rss feed newsletter