Class Index | File Index

Classes


Class KiiBucket

Represents a KiiBucket object
Defined in: KiiSDK.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
 
acl()
Get the ACL handle for this bucket

Any KiiACLEntry objects added or revoked from this ACL object will be appended to/removed from the server on ACL save.
 
count(callbacks)
Execute count aggregation of all clause query on current bucket.
 
countWithQuery(query, callbacks)
Execute count aggregation of specified query on current bucket.
 
Create a KiiObject within the current bucket

The object will not be created on the server until the KiiObject is explicitly saved.
 
Create a KiiObject within the current bucket, specifying its ID.
 
Create a KiiObject within the current bucket, with type

The object will not be created on the server until the KiiObject is explicitly saved.
 
delete(Object)
Delete the given bucket from the server
 
executeQuery(KiiQuery, Object)
Perform a query on the given bucket

The query will be executed against the server, returning a result set.
 
The name of this bucket
Class Detail
KiiBucket()
Method Detail
{KiiACL} acl()
Get the ACL handle for this bucket

Any KiiACLEntry objects added or revoked from this ACL object will be appended to/removed from the server on ACL save.
  	var bucket = . . .; // a KiiBucket
  	var acl = bucket.acl();
Returns:
{KiiACL} A KiiACL object associated with this KiiObject

{Promise} count(callbacks)
Execute count aggregation of all clause query on current bucket.
  // example to use callbacks directly
  var bucket = . . .; // a KiiBucket
  // define the callbacks
  var callbacks = {
      success: function(bucket, query, count) {
          // do something with the results
      },
  
      failure: function(bucket, errorString) {
          // error happened.
      }
  };
  
  bucket.count(callbacks);
  
  // example to use Promise
  var bucket = . . .; // a KiiBucket
  var queryObject = . . .; // a KiiQuery
  
  bucket.count().then(
      function(params) {
          var bucket = params[0];
          var count = params[2];
          // do something with the results
      },
      function(error) {
          var bucket = error.target;
          var errorString = error.message;
          // error happened.
      }
  );
Parameters:
{Object} callbacks Optional
An object with callback methods defined.
{Method} callbacks.success
The callback method to call on a successful query request.
{Method} callbacks.failure
The callback method to call on a failed query request.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is Array instance.
    • params[0] is a KiiBucket instance which this method was called on.
    • params[1] is a KiiQuery instance.
    • params[2] is an integer count result.
  • reject callback function: function(error). error is an Error instance.
    • error.target is the KiiBucket instance which this method was called on.
    • error.message

{Promise} countWithQuery(query, callbacks)
Execute count aggregation of specified query on current bucket. Query that passed as nextQuery in success callback of #executeQuery, is not supported, callbacks.failure will be fired in this case.
  // example to use callbacks directly
  var bucket = . . .; // a KiiBucket
  var queryObject = . . .; // a KiiQuery
  
  // define the callbacks
  var callbacks = {
      success: function(bucket, query, count) {
          // do something with the results
      },
  
      failure: function(bucket, errorString) {
          // error happened.
      }
  };
  
  bucket.countWithQuery(queryObject, callbacks);
  
  // example to use Promise
  var bucket = . . .; // a KiiBucket
  var queryObject = . . .; // a KiiQuery
  
  bucket.countWithQuery(queryObject, callbacks).then(
      function(params) {
          var bucket = params[0];
          var query = params[1];
          var count = params[2];
          // do something with the results
      },
      function(error) {
          var bucket = error.target;
          var errorString = error.message;
          // error happened.
      }
  );
Parameters:
{KiiQuery} query
to be executed. If null, the operation will be same as #count.
{Object} callbacks Optional
An object with callback methods defined.
{Method} callbacks.success
The callback method to call on a successful query request.
{Method} callbacks.failure
The callback method to call on a failed query request.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is Array instance.
    • params[0] is a KiiBucket instance which this method was called on.
    • params[1] is a KiiQuery instance.
    • params[2] is an integer count result.
  • reject callback function: function(error). error is an Error instance.
    • error.target is the KiiBucket instance which this method was called on.
    • error.message

{KiiObject} createObject()
Create a KiiObject within the current bucket

The object will not be created on the server until the KiiObject is explicitly saved. This method simply returns an empty working KiiObject.
  var bucket = . . .; // a KiiBucket
  var object = bucket.createObject();
Returns:
{KiiObject} An empty KiiObject with no specific type

{KiiObject} createObjectWithID(String)
Create a KiiObject within the current bucket, specifying its ID.

If the object has not exist on KiiCloud, KiiObject#saveAllFields(callback) will create new Object which has ID specified in the argument. If the object exist in KiiCloud, references the existing object which has specified ID. use KiiObject#refresh(callback) to retrieve the contents of KiiObject.
   var bucket = . . .; // KiiBucket
   var object = bucket.createObjectWithID('__OBJECT_ID_');
Parameters:
String
objectID ID of the obeject you want to instantiate.
Throws:
{InvalidArgumentException}
objectID is not acceptable. Refer to KiiObject.isValidObjectID(string) for details of acceptable string.
Returns:
{KiiObject} KiiObject instance.

createObjectWithType(String)
Create a KiiObject within the current bucket, with type

The object will not be created on the server until the KiiObject is explicitly saved. This method simply returns an empty working KiiObject with a specified type. The type allows for better indexing and improved query results. It is recommended to use this method - but for lazy creation, the createObject method is also available.
  var bucket = . . .; // a KiiBucket
  var object = bucket.createObjectWithType("scores");
Parameters:
String
type A string representing the desired object type
Returns:
An empty KiiObject with specified type

{Promise} delete(Object)
Delete the given bucket from the server
  // example to use callbacks directly
  var bucket = . . .; // a KiiBucket
  bucket.delete({
      success: function(deletedBucket) {
          // do something with the result
      },
  
      failure: function(bucketToDelete, anErrorString) {
          // do something with the error response
      }
  });
  
  // example to use Promise
  var bucket = . . .; // a KiiBucket
  bucket.delete({
      success: function(deletedBucket) {
          // do something with the result
      },
  
      failure: function(bucketToDelete, anErrorString) {
          // do something with the error response
      }
  }).then(
      function(deletedBucket) {
        // do something with the result
      },
      function(error) {
        // do something with the error response
      }
  );
Parameters:
Object
callbacks An object with callback methods defined
{Method} callbacks.success
The callback method to call on a successful query request
{Method} callbacks.failure
The callback method to call on a failed query request
Returns:
{Promise} return promise object.
  • fulfill callback function: function(deletedBucket). deletedBucket is KiiBucket instance.
  • reject callback function: function(error). error is an Error instance.
    • error.target is the KiiBucket instance which this method was called on.
    • error.message

{Promise} executeQuery(KiiQuery, Object)
Perform a query on the given bucket

The query will be executed against the server, returning a result set.
  // example to use callbacks directly
  var bucket = . . .; // a KiiBucket
  var queryObject = . . .; // a KiiQuery
  
  // define the callbacks (stored in a variable for reusability)
  var queryCallbacks = {
      success: function(queryPerformed, resultSet, nextQuery) {
          // do something with the results
          for(var i=0; i<resultSet.length; i++) {
              // do something with the object
              // resultSet[i]; // could be KiiObject, KiiGroup, KiiUser, etc
          }
  
          // if there are more results to be retrieved
          if(nextQuery != null) {
  
              // get them and repeat recursively until no results remain
              bucket.executeQuery(nextQuery, queryCallbacks);
          }
      },
  
      failure: function(bucket, anErrorString) {
          // do something with the error response
      }
  };
  bucket.executeQuery(queryObject, queryCallbacks);
  
  // example to use Promise
  var bucket = . . .; // a KiiBucket
  var queryObject = . . .; // a KiiQuery
  bucket.executeQuery(queryObject).then(
      function(params) {
          var queryPerformed = params[0];
          var resultSet = params[1];
          var nextQuery = params[2];
          // do something with the results
          for(var i=0; i<resultSet.length; i++) {
              // do something with the object
              // resultSet[i]; // could be KiiObject, KiiGroup, KiiUser, etc
          }
  
          // if there are more results to be retrieved
          if(nextQuery != null) {
  
              // get them and repeat recursively until no results remain
              bucket.executeQuery(nextQuery).then(
                  function(params) {
                      // next query success
                  },
                  function(error) {
                      // next query failed, please handle the error
                  }
              );
          }
  
      },
      function(error) {
          // do something with the error response
      }
  );
Parameters:
KiiQuery
query An object with callback methods defined
Object
callbacks An object with callback methods defined
{Method} callbacks.success
The callback method to call on a successful query request
{Method} callbacks.failure
The callback method to call on a failed query request
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is Array instance.
    • params[0] is a performed KiiQuery instance.
    • params[1] is resultSet Array instance. Could be KiiObject, KiiGroup, KiiUser, etc.
    • params[2] is a KiiQuery instance for next query. If there are no more results to be retrieved, it will be null.
  • reject callback function: function(error). error is an Error instance.
    • error.target is the KiiBucket instance which this method was called on.
    • error.message

{String} getBucketName()
The name of this bucket
Returns:
{String}

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Sep 15 2021 05:31:33 GMT-0000 (UTC)