Class ydn.db.Request

An instance of the Request class represents a result of a database request.

Extends: goog.async.Deferred

Method
abort()
Abort the transaction of the request.
var req = db.put('store1', obj).done(function (key) {
  if (key > 1000) {
    req.abort(); // request can be aborted because, transaction is not committed yet.
  }
});
Throws:
{!ydn.db.InvalidStateError} If no active transaction.

always(cb, opt_scope)
Register a callback function as both done and fail callbacks.
Raw method name: addBoth
Parameters:
{function(this: T, *)} cb
The function to be called with a result.
{T=} Optional. opt_scope
An optional scope to call the callback in.
Returns:
{!ydn.db.Request} This Deferred.

done(cb, opt_scope)
Register a callback function to be called with a successful result.

This is same as calling then method without fail callback.

Raw method name: addCallback

Parameters:
{function(this: T, *)} cb
The function to be called with a successful result.
{T=} Optional. opt_scope
An optional scope to call the callback in.
Returns:
{!ydn.db.Request} This Deferred.

canAbort()
Check whether request can be aborted.
Returns:
{boolean} Return true if the request can be aborted.

fail(cb, opt_scope)
Register a callback function to be called with a error result.

This is same as calling then method without done callback.

Raw method name: addErrback

Parameters:
{function(this: T, *)} cb
The function to be called with a error result.
{T=} Optional. opt_scope
An optional scope to call the callback in.
Returns:
{!ydn.db.Request} This Deferred.

state()
jquery
Determine the current state of a Deferred object.
Returns:
{string}Either one of 'pending', 'rejected' or 'resolved'.

then(done, fail, opt_scope)
Registers a callback function and an fail function at the same position in the execution sequence.

If no value is returned by the done callback function, the result value is unchanged. If a new value is returned, it becomes the Deferred result and will be passed to the next callback in the execution sequence. If the function throws an error, the error becomes the new result and will be passed to the next fail callback in the execution chain. If the function returns a promise or thenable, the execution sequence will be blocked until that Deferred fires. Its result will be passed to the next done callback (or fail callback if it is an error result) in this Deferred's execution sequence.

Raw method name: addCallbacks

Parameters:
{function(this: T, *)} done
The function to be called with a sucess result.
{function(this: T, *)} fail
The function to be called with a error result.
{T=} Optional. opt_scope
An optional scope to call the callback in.
Returns:
{!ydn.db.Request} This Deferred.

toJSON()
dev
JSON representation of this object.

Example JSON:

{
  branchNo: 0
  method: ["get", "iter"]
  requestNo: 1
  transactionNo: 8
}
Returns:
{!Object}JSON representation of this object.

toString()
dev
String representation of this object.
The returning string starts with 'Request', follow by request method and then transaction label if exists. Transaction label has serial numbers of branch, transaction and request, represented by B, T and R, respectively.
Returns:
{string}String representation of this object.