tables object
Provides functionality for working with specific tables as a table object instance.
Members
This object contains the following members:
Methods
getTable
Syntax |
Returns |
Description |
---|---|---|
tables.getTable(tableName) |
Returns the specified tableName as a table object. |
Properties
current
Syntax |
Returns |
Description |
---|---|---|
tables.current |
Returns the current table as a table object. |
Remarks
Call the getTable method on the global tables object to get a table object that represents a specific tableName.
The current property on the global tables object gets a table object that represents the current table.
Example
The following script calls the getTable method to get the permissions table against which to execute queries.
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.');
}
}
});
}
Example
The following script shows usage of the current property in validation logic.
function insert(item, user, request) {
var currentTable = tables.current;
currentTable.where({ name: item.name }).read({
success: function (items) {
if (items.length > 0) {
request.respond(400, { error: 'Item with this name already exists' });
} else {
request.execute();
}
}
});
}