Overview

Classes

 
 

API Reference

The CloudBoost API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and to use HTTP response codes to indicate API errors. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which can be understood by off-the-shelf HTTP clients, and we support cross-origin resource sharing to allow you to interact securely with our API from a client-side web application/mobile application (though you should remember that you should never expose your secret API master key in any public website's client-side code, Client Key can be exposed). JSON will be returned in all responses from the API, including errors (though if you're using API bindings/SDK, we will convert the response to the appropriate language-specific object).

JavaScript SDK

Non-minified :

https://cloudboost.io/js-sdk/cloudboost.js

Minified JS :

https://cloudboost.io/js-sdk/cloudboost.min.js

NPM :

npm install cloudboost var CB = require('cloudboost');

GitHub :

https://github.com/CloudBoost/JavaScriptSDK
 

Apps

In Cloudboost, you create an app each of which has its own AppID, Client Key and the Master Key that you apply to your web app. Your master key is a secret which should not be shared in your client apps. Your account on CloudBoost can accommodate multiple apps. This is useful even if you have one application since you can deploy different versions for test and production.

 

CB.CloudApp

 

CloudApp.init( appId, appKey )

Initialize's the Application with CloudBoost

For each Application you create, there are two keys provided by CloudBoost,

  1. #1 - Client Key
  2. #2 - Master Key

If you want a client of your app to have access to CloudBoost API, then its recommended to initiate your app with your respective ClientKey only.

We don't recommend you to initiate your app with MasterKey unless you install our API and make requests from your own server.

Arguments
appId
Application ID with which your app is registered. You can find this on your CloudBoost Dashboard
appKey
Client / Master key Secret Key for your app. You can find this on your CloudBoost Dashboard
Returns

void

CB.CloudApp.init('YOUR APP ID', 'YOUR APP KEY');
 

CB.CloudObject

This class represents data in CloudBoost.

Each instance of CB.CloudObject represents a row of table in Database. The data stored in CloudObject has schema which you can define in Table Designer in CloudBoost portal. CloudBoost is schema-mix, so you can store or validate the piece of data with a schema.

It allows you to store data in key-value pairs, in database designed by you.

 

Constructor : CloudObject( columnName, [objectId] )

Instantiates a CloudObject object.

Argument
tableName
string The name of the table in database
objectId
[optional] string The ID of the Object
Important : Use this parameter only when you're working on relations.
Returns

It returns an instance of a CloudObject, as its a constructor.

Properties

Every instance of CloudObject has these properties

id
string The id of the CloudObject which is populated after the object is saved.
createdAt
Date The Date and time when the object was saved in the database.
updatedAt
Date The Date and time when the object was updated in the database.
ACL
ACL Access Control List, by default this object is publicily readable and writeable. You set object level security here. Refer ACL's
//creates an object for Student table var obj = new CB.CloudObject("Student");
 

CloudObject.set( columnName, data )

Sets the value of an attribute of an instance of a CloudObject.

Arguments
columnName
string The name of the column whose value is to be set.
data
Any dataThe value which is to be stored in the column.
Returns

void

var obj = new CB.CloudObject('Student'); //create a new object. obj.set("name", "John Smith"); //store string obj.set("age", 21); // store number obj.set("address", { city: "Hyderabad", state: "Telangana", country: "India" }); // store in object
 

CloudObject.get( columnName )

Gets the value of a column of an instance of CloudObject.

Argument
columnName
string The name of the column whose value is to be fetched.
Returns

It returns the value of column which was previously set otherwise returns undefined if the column is not set to a value.

var address = obj.get('address'); //get the data. /* address will be { city: "Hyderabad", state: "Telangana", country: "India" } which was saved in the object using object.set */
 

CloudObject.unset( columnName )

Removes the value of a column of an instance of a CloudObject to null.

Argument
columnName
string The name of the column which is to be unset.
Returns

void

var obj = new CB.CloudObject('Student'); obj.set("name", "John Smith"); obj.get("name"); //returns John Smith. obj.unset("name"); obj.get("name"); //returns null.
 

CloudObject.save( [callback] )

Saves the instance of CloudObject to CloudBoost.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a Promise which when resolved and returns instance of CloudObject saved .If the promise is rejected, you get an error object back. (if callback is not provided).

var obj = new CB.CloudObject('Student'); obj.set("name", "Smith"); obj.save({ success: function(obj) { //Saving successfull //obj is instance of CloudObject }, error: function(err) { //Error occured in saving the object } });
 

CloudObject.fetch( [callback] )

Refreshes a CloudObject object by fetching its values from the database.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns Promise whcih resolves or rejects (if callback is not provided).

obj.fetch({ success: function(obj) { //obj is an instance of a refreshed CloudObject }, error: function(err) { //Error occurred in fetching the data } });
 

CloudObject.delete( [callback] )

Delete a CloudObject object, if it is saved in the database.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns Promise which resolves or rejects (if callback is not provided).

obj.delete({ success: function(obj) { //success }, error: function(err) { //Error } });
 

CloudObject.on( tableName, eventType, functionToFire, [callback] )

Realtime Notifications : Listens to CloudObject events like insert, update, delete in the database.

Argument
tableName
String Name of the table on which you want to listen for events. respective response.
eventType
String / Array Type of an event you want to listen to, Only created, updated, deleted are supported values.
functionToFire
Function Your custom function to fire when the event occours
callback
Object [optional] Success/Error callback if the subscribe to event was successful / failed.
Returns

It returns a Promise (if callback is not provided).

//listen to an event CB.CloudObject.on('Student', //name of the table 'created', //type of an event function(obj){ //your custom function which you want to fire. //obj is an instance of CloudObject console.log('Student Created : '+obj.get('name')); },{ //callback success : function(){ //subscribe success }, error : function(err){ //failed } });
 

CloudObject.off( tableName, eventType, [callback] )

Realtime Notifications : Switches off listening to CloudObject events like insert, update, delete in the database.

Argument
tableName
String Name of the table on which you want to stop listening for events to. respective response.
eventType
String / Array Type of an event you want to stop listening to, Only created, updated, deleted are supported values.
callback
Object [optional] Success/Error callback if the unsubscribe to event was successful / failed.
Returns

It returns a Promise (if callback is not provided).

//stop listening to an event CB.CloudObject.off('Student', //name of the table 'created', //type of an event { //callback success : function(){ //unsubscribe success }, error : function(err){ //unsubscribe failed } });
 

CloudObject.expires

Automatically deletes the object from the database at specified time. Sets the expiration time for CloudObject. Expiration time is to be given as number of milliseconds from 1 Jan 1970.

var obj = new CB.CloudObject('Student'); obj.set('name', 'John Smith'); expire=new Date().getTime()+1000; //increase the expiration time by 1 second from current time obj.expires = expires; //Set the expire time for object Student


 

CloudObject.relate(columnName,tableName,objectId)

Relates a CloudObject which is already saved to this CloudObject. Can be used to relate objects together in a relation.

Argument
columnName
String Name of the column of the current CloudObject.
tableName
String Name of the table of the CloudObject which you want to relate to.
objectId
String Id of the object which you want to relate to.
Returns

void

var obj = new CB.CloudObject('Student'); obj.relate('teacher','Teacher','xxxxxx'); //relates the teacher in the Teacher table with id xxxxx to this student.
 

CB.CloudObject.saveAll(ObjectArray, [callback])

Saves an Array of CloudObject.

Argument
ObjectArray
Array Array of CloudObjects.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

Array of Saved CloudObjects

var obj1 = new CB.CloudObject('Student'); obj1.set('name','abcd'); var obj2 = new CB.CloudObject('Student'); obj2.age('age',10); CB.CloudObject.saveAll([obj1,obj2]).then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

CB.CloudObject.deleteAll(ObjectArray, [callback])

Deletes an Array of CloudObject.

Argument
ObjectArray
Array Array of CloudObjects.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

Array of Deleted CloudObjects

CB.CloudObject.deleteAll([obj1,obj2]).then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

CB.CloudObject.pin( cloudObjects, [callback] )

Stores the CloudObjects to the local store

Argument
cloudObjects
Array Array of CloudObjects
callback
callback [optional] if provided must have success and error functions to handle respective response.
Returns

Array of Stored CloudObjects

CB.CloudObject.pin([obj1,obj2]).then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

CB.CloudObject.unPin( cloudObjects, [callback] )

Removes the CloudObjects from local store

Argument
cloudObjects
Array Array of CloudObjects
callback
callback [optional] if provided must have success and error functions to handle respective response.
Returns

Array of CloudObjects which are removed

CB.CloudObject.unPin([obj1,obj2]).then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

CB.CloudObject.saveEventually( [callback] )

Helps pin and save the CloudObject in local storage.

Argument
callback
callback [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a Promise which when resolved and returns instance of CloudObject saved .If the promise is rejected, you get an error object back. (if callback is not provided).

CB.CloudObject.saveEventually().then(function(res){ console.log(res); },function(err){ console.log(err); });
 

CB.CloudObject.clearLocalStore( [callback] )

Removes all the CloudObjects from the local store

Argument
callback
callback [optional] if provided must have success and error functions to handle respective response.
Returns

Array of CloudObjects which are removed

CB.CloudObject.clearLocalStore().then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

CB.CloudObject.sync( [callback] )

To fetch all CloudObjects from Local Storage

Argument
callback
callback [optional] if provided must have success and error functions to handle respective response.
Returns

Array of CloudObjects which are stored in Local Storage

CB.CloudObject.sync().then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

CB.CloudObject.disableSync( [callback] )

To diable sync of CloudObjects from Local Storage

Argument
callback
callback [optional] if provided must have success and error functions to handle respective response.
Returns

Array of CloudObjects which are stored in Local Storage

CB.CloudObject.disableSync().then(function(res){ console.log(res); },function(err){ console.log(err); } );
 

Relationships

This section is dedicated to modelling relationships with CloudBoost.

There are usually three types of relationships.

  • One-to-One Relationship
  • One-to-many Relationship
  • Many-to-many Relationship

 

One-to-One Relationship

If you want to model one-to-one relationship. Then you need to create a new column of type Relation pointed to a table which you want it to be related to and set that column Unique property to true.

var student = new CB.CloudObject("Student"); var address = new CB.CloudObject("Address"); //here one student can only have one address for example. //address column of Student Table is pointed to the Address Table with unique set to true. student.set('address', address); student.save({ success : function(student){ //saved }, error : function(err){ //error } });
 

One-to-Many Relationship

If you want to model one-to-many relationship. Then you need to create a new column of type Relation pointed to a table which you want it to be related to and set that column Unique property to false.

var teacher = new CB.CloudObject("Teacher"); var course = new CB.CloudObject("Course"); //here one teacher can be assigned to many courses. course.set('teacher', teacher); course.save({ success : function(course){ //saved course with teacher. }, error : function(err){ //error } });
 

Many-to-Many Relationship

If you want to model many-to-many relationship. Then you have two options

  1. #1 - Relation
  2. #2 - List


We will discuss both of these options below.


Relation :

This option is recommended only if you have huge number of relationships assigned to any one object.

This relationship can be created by creating a third table and having two columns that are relatied to tables you want to have many to many relationships on.











List Option

This option is recommended only if you have small number of relationships assigned to any one object.

This relationship can be created by creating an array and having related objects pushed to that array and having that array saved in any column of the table.

//Type #1 : Relation Option var student = new CB.CloudObject("Student"); var course = new CB.CloudObject("Course"); //here one student be into many courses, and vice versa. var studentCourse = new CB.CloudObject('StudentCourse'); studentCourse.set('student', student); studentCourse.set('course', course); studentCourse.save({ success : function(studentCourse){ //saved studentCourse with two related objects. }, error : function(err){ //error } }); //Type #2 : List Option. var student = new CB.CloudObject("Student"); //create an array. var courseList = []; //a new course var course = new CB.CloudObject("Course"); //add it to the list. You can push any number of objects you need. courseList.push(course); //here one student be into many courses, and vice versa. student.set('courses', courseList); //save student.save({ success : function(student){ //saved student with two related objects. }, error : function(err){ //error } });
 

Query on Relationships

Relations are of two types and if you want to query relationships then there is a different type of query for each of the type. Two types are :

  1. #1 - Relation
  2. #2 - List


We will discuss both of these options below.


Relation :

To query on a Relation, You can use CloudQuery function EqualTo / NotEqualTo









List Option

To query on a List of Relations , You can use CloudQuery function ContainedIn / NotContainedIn / ContainsAll

//Type #1 : Relation Option. //Get all the course which belong to a teacher var courseQuery = new CB.CloudQuery('Course'); courseQuery.equalTo('teaher', teacher); //teacher is an instance of CloudObject and should have an Id. courseQuery.find({ success : function(list){ //list of CloudObject }, error : function(error){ //error } }); //Type #2 : Query on List of Relations. //Get all the courses which the student belongs to. //Assume : Course has a list of Students, in the column 'students' var courseQuery = new CB.CloudQuery('Course'); courseQuery.containsIn('student', student); //student is an instance of CloudObject and should have an Id. courseQuery.find({ success : function(list){ //list of CloudObjects }, error : function(error){ //error } });
 

CloudQuery

It encapsulates a set of methods and attributes required to query your data in CloudApp to retrieve desired set of results.

 

Constructor

Instantiates a CloudQuery object.

Argument
tableName
string The name of the table you want to query on.
Returns

void

var query = new CB.CloudQuery("Student");
 

CloudQuery.all( columnName )

Return's true if the result matches with all of the values of given columnName, similar to keyword any in SQL Query's.

Primarily, used to run nested queries.

Argument
columnName
string The column name on which operation is to be performed.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.all('course'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.any( columnName )

Return's true if the result matches with any one values of given columnName, similar to keyword any in SQL Query's.

Primarily, used to run nested queries.

Argument
columnName
string The column name on which operation is to be performed.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.any('first_name'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.first( columnName )

Return's true if the result matches with very first value of given columnName.

Primarily, used to run nested queries.

Argument
columnName
string The column name on which operation is to be performed.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.first('teacher'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.search( search, language, caseSensitive, diacriticSensitive )

It allows you to search on basis of criteria provided by you.

Arguments
search
string The Query you want to fire on database
language
string[optional] The type of language you want to specify
caseSensitive
boolean[optional] true/false
diacriticSensitive
boolean[optional] true/false
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.search('my_string'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.equalTo( columnName, data )

It adds a constriant for finding the subset of the data in which columnName is equal to data.

Arguments
columnName
string The column on which the constraint is to be applied
data
AnythingThe value of the equals constraint
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.equalTo('age', 21); //find all Students who age is 21 query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.notEqualTo( columnName, data )

It adds a constriant for finding the subset of the data in which columnName does not has the value data.

Arguments
columnName
string The attribute on which the constraint is to be applied
data
AnythingThe value of the equals constraint
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); //find all Students info except of Smith query.notEqualTo('name', 'Smith'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.delete( callback )

It deletes all the data from Table

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

void

var query = new CB.CloudQuery("Student"); query.delete();
 

CloudQuery.containedIn( columnName, data )

If you want to retrieve objects matching several different values, you can use containedIn, providing an array of acceptable values. This is often useful to replace multiple queries with a single query.

Arguments
columnName
string The name of the column whose value is to be checked
data
Array The value(s) that are to be matched with.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); //Get Student where name is equal to Smith, Max OR Lucy query.containedIn('name', ['Smith', 'Max', 'Lucy']); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.containsAll( columnName, data )

Find objects where the array data in columnName contains all of the elements of data.

Arguments
columnName
string The name of the column whose value is to be checked
data
Array The value(s) that are to be matched with.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); //find Students who are in JavaScript AND C# class query.containsAll('classes', ['JavaScript', 'C#']); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.notContainedIn( columnName, data )

If you want to retrieve objects which doesn't include certain values, you can use notContainedIn, providing an array of acceptable values. This is often useful to replace multiple queries with a single query.

Arguments
columnName
string The name of the column whose value is to be checked
data
Array The value(s) that are to be matched with.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); //Get all Students except Smith, Max and Lucy query.notContainedIn('name', ['Smith', 'Max', 'Lucy']); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.greaterThan( columnName, data )

It adds a constraint for finding the subset of the data in which columnName has the value greater than data.

Arguments
columnName
string The attribute on which the constraint is to be applied
data
string / numberThe value of the equals constraint
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Teacher"); //find all the teachers who are old. query.greaterThan('age', 60); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.greaterThanEqualTo( columnName, data )

It adds a constraint for finding the subset of the data in which columnName has the value greater than or equals to data.

Arguments
columnName
string The attribute on which the constraint is to be applied
data
string / numberThe value of the equals constraint
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Teacher"); query.greaterThanEqualTo('age', 60); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.lessThan( columnName, data )

It adds a constraint for finding the subset of the data in which columnName has the value less than data.

Arguments
columnName
string The attribute on which the constraint is to be applied
data
string/numberThe value of the equals constraint
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.lessThan('age', 18); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.lessThanEqualTo( columnName, data )

It adds a constraint for finding the subset of the data in which columnName has the value less than or equals to data.

Arguments
columnName
string The attribute on which the constraint is to be applied
data
string/numberThe value of the equals constraint
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.lessThanEqualTo('age', 17); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.startsWith( columnName, data )

It adds a constraint to find the data in which value of columnName of each data is starts with data.

Arguments
columnName
string The name of the column whose value is to be checked
data
string The value that is to be checked with.
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); //find all the Students who name starts with letter 'S' query.startsWith('name', 'S'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.or( query1, query2 )

It adds a logical OR constraint between 2 CloudQuery objects for finding the set of the data satisfying conditions of both query1 and query2.

Both of the CloudQuery objects should be of the same collection otherwise it throws an error.

Arguments
query1
CloudQuery object
query2
CloudQuery object
Returns

It returns a CloudQuery object which contains OR'ed query of both of the CloudQuery objects.

//find all Student such that 10<age<18 var query1 = new CB.CloudQuery('Student'); query1.lessThan('age', 18); var query2 = new CB.CloudQuery('Student'); query2.greaterThan('age', 10); var query = CB.CloudQuery.or(query1, query2); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.orderByAsc( columnName )

It adds a constraint for arranging the subset of the data in ascending order.

Argument
columnName
string The attribute on which the constraint is to be applied
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.orderByAsc('age'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.orderByDesc( columnName )

It adds a constraint for arranging the subset of the data in descending order.

Argument
columnName
string The attribute on which the constraint is to be applied
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.orderByDesc('age'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.setLimit( data )

It adds a constraint to limit no. of the data to be fetched from the database.

If it is not set explicitly, database returns 20 results by default.

Argument
data
number No. of data to be shown
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.setLimit(5); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.setSkip( data )

It adds a constraint to skip data no. of data matching satisfying the query constraints and fetching from the database.

It requires a sort constraint and if none of it is provided by the user then the documents are sorted according to the createdAt attribute associated with the data.

Argument
data
number No. of data to be skipped
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.setSkip(5); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.paginate( pageNo, totalItemsInPage, [callback])

Paginate returns only the specified number of objects from the database. It takes in the current page number and total items in page as parameters and returns list of objects,count,total number of pages.

Argument
pageNo
number Current page number
totalItemsInPage
number total items in page
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

List of objects,count,total number of pages

var query = new CB.CloudQuery("Student"); query.paginate( 2, 10, { success: function(objectsList, count, totalPages){ //objectsList is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.selectColumn( columnNames )

It adds a constraint limiting the columns that are to fetched for each of the data from the database.

id, createdAt, updatedAt and ACL are always returned unless explicitly provided by the user to discard it using doNotSelectColumn()

Argument
columnNames
string/Object/Array The name of the column(s) that are to be returned
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.selectColumn(['name', 'age']); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.doNotSelectColumn( columnNames )

It adds a constraint restricting the columns given in columnNames to be fetched for each of the data from the database.

Argument
columnNames
string/Object/Array The name of the column(s) that are not to be returned
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.greaterThan('age', 18); query.doNotSelectColumn('address'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.exists( columnName )

It adds a constraint for finding the subset of the data in which columnName exists irrespective of what its value is.

Argument
columnName
string The column name which is to be checked for existence
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.exists('address'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.doesNotExists( columnName )

It adds a constraint for finding the subset of the data in which columnName does not exists.

Argument
columnName
string The column name which is to be checked for non-existence
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery("Student"); query.doesNotExists('address'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.find( [callback] )

Queries the database on the constraints provided by the CloudQuery object and gets the result as an array of CloudObject objects.

If no. of documents to be returned is not specified using limit() then at max 20 documents are returned in each query by default.

If no. of documents to be skipped is specified using skip() without sorting parameter then the documents matching the query provided in CloudQuery object are sorted in ascending order of createdAt field.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns an array of CloudObject objects or an error object if the opertion is successful or fails respectively along with JQuery promise (if callback is not provided).

query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.findOne( [callback] )

Queries the database on the constraints provided by the CloudQuery object and gets a single CloudObject object satisfying the constraint.

If no. of documents to be skipped is specified using skip() without sorting parameter then the documents matching the query provided in CloudQuery object are sorted in ascending order of createdAt field.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudObject object or an error object if the opertion is successful or fails respectively along with JQuery promise (if callback is not provided). It throws an error too if sufficient data is not available to query the database

query.findOne({ success: function(obj){ //obj is an instance of CloudObject }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.findFromLocalStore( [callback] )

Queries the database on the constraints provided by the CloudQuery object and gets a single CloudObject object satisfying the constraint.

If no. of documents to be skipped is specified using skip() without sorting parameter then the documents matching the query provided in CloudQuery object are sorted in ascending order of createdAt field.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudObject object or an error object if the opertion is successful or fails respectively along with JQuery promise (if callback is not provided). It throws an error too if sufficient data is not available to query the database

query.findFromLocalStore({ success: function(obj){ //obj is an instance of CloudObject }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.findById( [callback] )

Queries the database on the constraints provided by the CloudQuery object and gets a single CloudObject object satisfying the constraint.

If no. of documents to be skipped is specified using skip() without sorting parameter then the documents matching the query provided in CloudQuery object are sorted in ascending order of createdAt field.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudObject object or an error object if the opertion is successful or fails respectively along with JQuery promise (if callback is not provided). It throws an error too if sufficient data is not available to query the database

query.findById({ success: function(obj){ //obj is an instance of CloudObject }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.get( id, [callback] )

Queries the database gets a CloudObject object whose id field matches id.

Arguments
id
string The ID of the data which is to be matched with _id field in the database.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudObject object or an error object if the opertion is successful or fails respectively along with JQuery promise (if callback is not provided). It throws an error too if sufficient data is not available to query the database

query.get('xxxxx', { success: function(obj){ //obj an instance of CloudObject }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.count( [callback] )

It adds a constraint to find the data in which value of columnName of each data is at least equal to all of the value(s) provided in data.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns an Integer which is the number of documents matching the constraints given in the CloudQuery object along with JQuery promise (if callback is not provided).

query.count({ success: function(count){ //count is the count of data which belongs to the query }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.distinct( columnName, [callback] )

It returns distinct objects which have columnName

Sort parameter is required and if not provided by the user then ascending order sorting on createdAt field is applied by default.

Argument
columnName
String The column name which should have distinct values in the returned data set.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns an array of CloudObject objects which are documents matching the given query in the CloudQuery object having distinct values of ColumnName along with JQuery promise (if callback is not provided).

query.distinct('address', { success: function(data){ //data is an array of document(s) }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.include( columnName )

It gives the join on columnName for the table being queried upon.

Argument
columnName
String The column name on which join is to be performed.
Returns

Same query object, which can be helpful in chaining query functions.

//joins table student with hostel var query = new CB.CloudQuery("Student"); query.include('hostel'); query.find({ success: function(list){ //list is an array of CloudObjects }, error: function(err) { //Error in retrieving the data. } });
 

CloudQuery.near( columnName ,geoPoint, range )

Queries for CloudObject objects which are within range.It gives result in the order of nearest to farthest.

Argument
ColumnName
String Name of column which has the CloudGeoPoint
CloudGeoPoint
Object It is the point close to which the points are to be found respective response.
Range
Number It the range within which are CloudObjects are to be sought. It is given in Meters
Returns

Same query object, which can be helpful in chaining query functions.

var loc = new CB.CloudGeoPoint(17.7,80.3); var query = new CB.CloudQuery('Custom5'); query.near("location", loc, 100000); query.find().then(function(list) { //searches for cloudobjects within 100000 meters }, function (err) { //error }) });
 

CloudQuery.geowithin( ColumnName, CloudGeoPoint, Radius )

Queries for CloudObject objects which are within range.

Argument
ColumnName
Object Name of column which has the CloudGeoPoint
CloudGeoPoints
Array Array of CloudGeopoints within which we want to search CloudObjects or Center of Circle in case the shape is circle
Radius
decimal [Optional] Radius of Circle. Radius is taken in Meters
Returns

Same query object, which can be helpful in chaining query functions.

var loc1 = new CB.CloudGeoPoint(18.4,78.9); var loc2 = new CB.CloudGeoPoint(17.4,78.4); var loc3 = new CB.CloudGeoPoint(17.7,80.4); var query = new CB.CloudQuery('Custom'); query.geoWithin("location", [loc1, loc2, loc3]); query.find().then(function(list) { //searches for cloudobjects within triangle formed by the CloudGeoPoints }, function (err) { //error }) });
 

CloudQuery.regex( columnName, value, isCaseInsensitive )

Queries for CloudObject objects which matches given regular expression.

Argument
columnName
Object Name of column which has the CloudGeoPoint
value
String Value of the Regular Expression
isCaseInsensitive
boolean [optional] true/false
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery('Student'); query.regex(username, "/a", true); query.find().then(function(list) { //searches for cloudobjects within triangle formed by the CloudGeoPoints }, function (err) { //error }) });
 

CloudQuery.substring( columnName, value, isCaseInsensitive )

Queries for CloudObject objects whose column values contains the given substring.

Argument
columnName
Object Name of column which has the CloudGeoPoint
value
String Value of the substring to be matched
isCaseInsensitive
boolean [optional] true/false
Returns

Same query object, which can be helpful in chaining query functions.

var query = new CB.CloudQuery('Student'); query.substring(username, "as a", false); query.find().then(function(list) { //searches for cloudobjects within triangle formed by the CloudGeoPoints }, function (err) { //error }) });
 

CloudNotifcations

In Cloudboost, you can create realtime notification channels, publish messages to those channels and have other clients listen to those messages which are being published in real time.

 

CloudNotification.on( channelName, functionToFire, [callback] )

Listens to notification channels.

Arguments
channelName
Stringchannel to listen to.
functionToFire
function function to fire when data on this channel is published.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

CB.CloudNotification.on('Sample',function(data){ console.log(data); });
 

CloudNotification.publish( channelName, data, [callback] )

Publishes data to notification channels.

Arguments
channelName
Stringchannel to publish to.
data
Anything data you want to publish to this channel
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

CB.CloudNotification.publish('sample','data');
 

CloudNotification.off( channelName, [callback] )

Stops listening to notification channel.

Arguments
channelName
Stringchannel to stop listening to.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

CB.CloudNotification.off('sample');
 

Cloud Push Notifcations

In Cloudboost, you can send push notifications. Push notifications are a very important feature in an app because it enables seamless communication from your server to your app.

 

CB.CloudPush.send( dataJSON, cloudQuery/ChannelArray/SingleChannelString, [callback] )

Sending push notifications

Arguments
dataJSON
Object [required] must have message property, and title ,icon are optional. icon is only aplicable for android and IOS.
Query/Channels
cloudQuery or ChannelArray or ChannelString you can make queries on sending push notifications, it can be cloudQuery on Device table or Single Channel string or Channel Array.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

var query = new CB.CloudQuery("Device"); query.containedIn('channels', "hackers"); CB.CloudPush.send({message:"my first notifications"},query,{ success:function(){ //Success }, error:function(error){ //Error } });
 

CB.CloudPush.enableWebNotifications( [callback] )

When fired turns on the Web Notificaitons for your Application.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

var query = new CB.CloudQuery("Device"); query.containedIn('channels', "hackers"); CB.CloudPush.enableWebNotifications({ success:function(){ //Success }, error:function(error){ //Error } });
 

CB.CloudPush.disableWebNotifications( [callback] )

When fired turns off the Web Notificaitons for your Application.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

var query = new CB.CloudQuery("Device"); query.containedIn('channels', "hackers"); CB.CloudPush.disableWebNotifications({ success:function(){ //Success }, error:function(error){ //Error } });
 

CB.CloudPush._addDevice( deviceOS, endPoint, browserKey, authKey, [callback] )

Adds a device for Push Notificaitons

Arguments
deviceOS
String OS of the device on which notifications is to be sent
endPoint
String DeviceToken to uniquely identify device
browserKey
String if provided must have success and error functions to handle respective response.
authKey
String if provided must have success and error functions to handle respective response.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

CB.CloudPush._addDevice("android", "xxxx", "deviceToken", "xyxy", "auth_key",{ success:function(){ //Success }, error:function(error){ //Error } });
 

CB.CloudPush._deleteDevice( deviceOS, endPoint, [callback] )

Deletes a device being registered for Push Notificaitons

Arguments
deviceOS
String OS of the device on which notifications is to be sent
endPoint
String DeviceToken to uniquely identify device
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns JQuery promise, if callback is not specified

var query = new CB.CloudQuery("Device"); query.containedIn('channels', "hackers"); CB.CloudPush._deleteDevice("Android","xxxx",{ success:function(){ //Success }, error:function(error){ //Error } });
 

CB.CloudGeoPoint

CloudGeoPoint is used to store GeoPoints and perform GeoPoint operation like finding points near and bounding box.

A CloudGeoPoint object has to be saved in CloudObject in a column.

All the modifications in the GeoPoint can be reflected only after the object is saved after the changes.

 

Constructor

Init's a CloudGeoPoint object.

Argument

It takes latitude and longitude of a GeoPoint. Points can be given in Numeric format.

Returns

It returns a CloudGeoPoint object.

var point = new CB.CloudGeoPoint(17.4,78.5);
 

CloudGeoPoint.distanceInKms(CloudGeoPoint)

Finds distance between CloudGeoPoints in kilometers.

Argument
CloudGeoPoint
Object It is the point from which the distance to be found.
Returns

Distance in Kilometers.

var loc = new CB.CloudGeoPoint(17.7,80.3); var loc2 = new CB.CloudGeoPoint(10.7,70.3); var distance = loc.distanceInKMs(loc2);
 

CloudGeoPoint.distanceInMiles(CloudGeoPoint)

Finds distance between CloudGeoPoints in Miles.

Argument
CloudGeoPoint
Object It is the point from which the distance to be found.
Returns

Distance in Miles.

var loc = new CB.CloudGeoPoint(17.7,80.3); var loc2 = new CB.CloudGeoPoint(10.7,70.3); var distance = loc.distanceInMiles(loc2);
 

CloudGeoPoint.distanceInRadians(CloudGeoPoint)

Finds distance between CloudGeoPoints in kilometers.

Argument
CloudGeoPoint
Object It is the point from which the distance to be found.
Returns

Distance in Radians.

var loc = new CB.CloudGeoPoint(17.7,80.3); var loc2 = new CB.CloudGeoPoint(10.7,70.3); var distance = loc.distanceInRadians(loc2);
 

CB.CloudUser

There is a notion of user accounts that lets users access their information in a secure manner. We provide a specialized user class called CB.CloudUser that automatically handles much of the functionality required for user account management.

CB.CloudUser is a subclass of CB.CloudObject, and has all the same features, such as flexible schema, automatic persistence, and a key value interface. All the methods that are on CB.CloudObject also exist in CB.CloudUser. The difference is that CB.CloudUser has some special additions specific to user accounts. With this class, you'll be able to add user account functionality in your app.

There is a special object CB.CloudUser.current which holds the information of the current user logged in.

 

Constructor

Instantiates a CloudUser object.

Argument

It takes no argument.

var obj = new CB.CloudUser();
 

CloudUser.signUp( [callback] )

It registers new user given its username, email and password. Registration is successful if the given email is not already registered to an existing user.

It sets the attributes of CB.CloudUser.current object with the CloudUser object recieved.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudUser object which has the user information if registration is successful otherwise an error object along with JQuery promise (if callback is not provided).

var user = new CB.CloudUser(); user.set('username', 'my_username'); user.set('password', 'my_solid_password'); user.set('email', [email protected]'); user.signUp({ success: function(user) { //Registration successfull }, error: function(err) { //Error in user registration. } });
 

CloudUser.logIn( [callback] )

It logs in user given its username and password. Login is successful if the given username and password pair is already present in the database.

It sets the attributes of CB.CloudUser.current object with the CloudUser object recieved.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudUser object which has the user information if registration is successful otherwise an error object along with JQuery promise (if callback is not provided).

var user = new CB.CloudUser(); user.set('username', 'my_username'); user.set('password', 'my_solid_password'); user.logIn({ success: function(user) { //Login successfull }, error: function(err) { //Error occured in user registration. } });
 

CloudUser.logOut( [callback] )

It logs the user out.

It sets the CB.CloudUser.current object to null.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudUser object having the user information of the user who was logged in otherwise an error object along with JQuery promise (if callback is not provided).

CB.CloudUser.current.logOut({ success: function(user) { //log out successfull }, error: function(err) { //Error occured in user registration. } });
 

CloudUser.getCurrentUser( [callback] )

It gives the current value for CB.CloudUser.current object.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudUser object having the user information of the user who was logged in otherwise an error object along with JQuery promise (if callback is not provided).

CB.CloudUser.getCurrentUser({ success: function(user) { //success }, error: function(err) { //error } });
 

CloudUser._getCurrentUser()

It gets the current user from the cookie or from local storage.

Argument
No Arguments
Returns

It returns a CloudUser object having the user information of the user who was logged in otherwise null.

//returns current user from local storage var current_user = CB.CloudUser._getCurrentUser();
 

CloudUser.current( [callback] )

Get the current logged in user.

//gets the current user if user is loggedIn, null otherwise. var currentUser = CB.CloudUser.current;
 

CloudUser._setCurrentUser()

It sets the value of current user to the user who is currently logged in.

Argument
user
CloudUser Instance of CB.CloudUser Object which holds the information for current User who is logged in.
Returns

void

var user = CB.CloudUser(); user.set('username', 'my_username'); user.set('password', 'my_solid_password'); user.set('email', [email protected]'); CB.CloudUser._setCurrentUser(user);
 

CloudUser._removeCurrentUser()

It sets the value of current user to null.

Argument
No Argument
Returns

void

//removes the current user CB.CloudUser._removeCurrentUser(user);
 

CloudUser.authenticateWithProvider( dataJson, [callback] )

Used for authenticating the user with providers such as Twitter, Facebook and Google.

Arguments
dataJson
JSON Object JSON Object consisting of neccessary fields required for authentication.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a JQuery promise (if callback is not provided).

var dataJson = {provider : "twitter", accessToken : "zzzz" , accessSecret : "xxxx"}; //for others accessSecret is not required CB.CloudUser.authenticateWithProvider(dataJson, { success: function(user) { //Success }, error: function(err) { //Error } });
 

CloudUser.addToRole( role, [callback] )

A user can be a part of many roles, like in real world. For this functionality user should get added to a Role.

For this purpose addToRole() of CB.CloudUser comes in handy.

Arguments
role
CloudRole Object The CloudRole object of the role you want to add the user to.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudUser object having the user information of the user who was logged in otherwise an error object along with JQuery promise (if callback is not provided).

//role is an instance of CloudRole Object. CB.CloudUser.current.addToRole(role, { success: function(user) { //added to role successfull }, error: function(err) { //Error occured in adding to role. } });

Given getRole() is discussed later

 

CloudUser.isInRole( role )

To check if the current user is in the role provided by the role object.

Argument
role
CloudRole Object The CloudRole object of the role you want to check the user to.
Returns

It returns a true/false based on whether the user is in the given role or not respectively.

//role is the instance of the CloudRole object. if(CB.CloudUser.current.isInRole(role)) { //The current user is in the given role. } else { //The user is not in the given role. } }

Given getRole() is discussed later

 

CloudUser.removeFromRole( role , [callback] )

Removes the user from the given role provided in role object.

Argument
role
CloudRole Object The CloudRole object of the role you want to remove the user from.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a CloudUser object having the user information of the user who was logged in otherwise an error object along with JQuery promise (if callback is not provided).

CB.CloudUser.current.removeFromRole(role, { success : function(user){ //get the updated user }, error : function(err){ //erorr if something goes wrong. } }); }

Given getRole() is discussed later

 

CloudUser.changePassword( oldPassword, newPassword, [callback] )

Used to change the password for current user.

Argument
oldPassword
string The old password that you want to change
newPassword
string The new password that you want to keep
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a JQuery promise (if callback is not provided).

CB.CloudUser.current.changePassword("my_solid_password", "my_rock_solid_password", { success : function(user){ //get the updated user }, error : function(err){ //erorr if something goes wrong. } }); }
 

CloudUser.resetPassword( email, [callback] )

Used to reset the password for current user.

Argument
email
string The email_id which is registered with the CloudBoost
Object [optional] if provided must have success and error functions to handle respective response.
Returns

It returns a JQuery promise (if callback is not provided).

CB.CloudUser.current.resetPassword("[email protected]", { success : function(user){ //get the updated user }, error : function(err){ //erorr if something goes wrong. } }); }
 

CB.CloudRole

As your app grows in scope and user-base, you may find yourself needing more coarse-grained control over access to pieces of your data than user-linked ACLs can provide. To address this requirement, CloudBoost supports a form of Role-based Access Control. Roles provide a logical way of grouping users with common access privileges to your CB data. Roles are named objects that contain users and other roles. Any permission granted to a role is implicitly granted to its users as well as to the users of any roles that it contains.

We provide a specialized class called CB.CloudRole that represents these role objects in your client code. CB.CloudRole is a subclass of CB.CloudObject, and has all of the same features, such as a flexible schema, automatic persistence, and a key value interface. All the methods that are on CB.CloudObject also exist on CB.CloudRole. The difference is that CB.CloudRole has some additions specific to management of roles.

 

Constructor

Instantiates a CloudRole object.

Argument
roleName
string The name of the role you want to deal with
var role = new CB.CloudRole("Student");
 

CB.CloudFile

CB.CloudFile lets you store application files in the cloud that would otherwise be too large or cumbersome to fit into a regular CB.CloudObject. The most common use case is storing images, but you can also use it for documents, videos, music, and any other binary data.
 

Constructor

Instantiates a CloudFile object.

Argument
file
file/BLOB objectThe file/BLOB that you want to save
var documentFile = new Blob(['This is the content of by document blob'], {type : 'text/plain'}); var file = new CB.CloudFile(documentFile);
 

CloudFile.save( [callback] )

Saves the CloudFile object.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns a CloudFile object having url attribute set to the URL of the blob uploaded to the server if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var documentFile = new Blob([ 'This is the content of by document blob' ], { type : 'text/plain' }); var file = new CB.CloudFile(documentFile); file.save({ success: function(roleObj) { //got the file object successfully with the url to the file }, error: function(err) { //error in uploading file } });
 

CloudFile.delete( [callback] )

Saves the CloudFile object.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns a CloudFile object having url attribute set to null if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
file.delete({ success: function(fileObj) { //file deletion successful }, error: function(err) { //error in deleting file } });
 

CloudFile.fetch( [callback] )

Fetches the CloudFile object which has the URL along with other Properties of File.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns a CloudFile object having url if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var query = new CB.CloudQuery("Custom"); query.find().then(function(res) var file = res.get('file'); file.fetch({ success: function(roleObj) { //Gets File Object }, error: function(err) { //error in geting file } },function(){ //error querying object }); });
 

CloudFile.getFileContent( [callback] )

Get's the CloudFile content.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudFile object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var query = new CB.CloudQuery("Custom"); query.find().then(function(res) var file = res.get('file'); file.fetch({ success: function(fileObj) { fileObj.getFileContent({ success: function(fileObj) { //Gets the Content of the File Pointed By File Object }, error: function(err) { //error in getting File Content }); //Gets File Object }, error: function(err) { //error in getting file }) },function(){ //error querying object }); });
 

CB.CloudCache

CB.CloudCache lets you store information/data in the cloud allowing you to fetch the same at higher speed. The most common use case is storing the information/data which is shareable and is often used by Application at regular intervals.
 

Constructor

Instantiates a CloudCache object.

Argument
cacheName
stringThe name of the cache you want to create
var cache = new CB.CloudCache("myCache");
 

CloudCache.set( key, value, [callback] )

Sets the CloudCache with data.

Argument
key
string The key with which you want to refer the information.
value
string/Object The value which you want to store.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns a CloudCache object having cache information if callback is defined on success, otherwise returns an error object along with JQuery promise (if callback is not provided).
var data = "some_useful_info"; var cache = new CB.CloudCache("myCache"); cache.set("key1",data,{ success: function(cacheObj){ //success }, error: function(err){ //error } });
 

CloudCache.deleteItem( key, [callback] )

Deletes the data related to the key provided as parameter.

Argument
key
string The key which needs to be deleted.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns a CloudCache object having cache information on success, or JQuery Promise on error.
var cache = new CB.CloudCache("myCache"); cache.deleteItem("key1",{ success: function(cacheObj){ //success }, error: function(err){ //error } });
 

CloudCache.create( [callback] )

Creates a URL for your cache

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns a CloudCache object having url if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); cache.create({ success: function(cacheObj){ //success }, error: function(err){ //error } });
 

CloudCache.get( key, [callback] )

Get's the information from CloudCache related to the particular key.

Argument
key
string The key corresponding to informtaion you want to retrieve.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); //set the data here var data = cache.get("key1", { success: function(cacheObj){ //success }, error: function(err){ //error });
 

CloudCache.getInfo( [callback] )

Get's the whole cache from CloudCache.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); var data = cache.getInfo({ success: function(cacheObj){ //success }, error: function(err){ //error });
 

CloudCache.getItemsCount( [callback] )

Get's the count of items being present in CloudCache.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); var count = cache.getItemsCount({ success: function(cacheObj){ //success }, error: function(err){ //error });
 

CloudCache.getAll( [callback] )

Get's the whole cache from CloudCache.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); var data = cache.getInfo({ success: function(cacheObj){ //success }, error: function(err){ //error });
 

CloudCache.clear( [callback] )

Clears the cache content from CloudCache.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); var returnObj = cache.clear();
 

CloudCache.delete( [callback] )

Deletes the whole cache from CloudCache.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var cache = new CB.CloudCache("myCache"); cache.delete({ success: function(cacheObj){ //success }, error: function(err){ //error });
 

CloudCache.deleteAll( [callback] )

Deletes all cache present from CloudCache.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudCache object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
CB.CloudCache.deleteAll({ success: function(cacheObj){ //success }, error: function(err){ //error });
 

CB.CloudQueue

CB.CloudQueue lets you line up events in FIFO(First In First Out) manner. The most common use case is for triggering events in the order that they are pushed into the CloudQueue.
 

Constructor

Instantiates a CloudQueue object.

Argument
queueName
stringThe name of the queue that you want to create.
queueType
stringCan be either push or pull
var queueName = "myQueue"; var queueType = "push"; var queue = new CB.CloudQueue(queueName,queueType);
 

CloudQueue.addMessage( queueMessage, [callback] )

Adds a message to the CloudQueue object.

Argument
queueMessage
string The message that you want to add to the Queue.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
var queue = new CB.CloudQueue("myQueue","push"); queue.addMessage("Message String",{ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.updateMessage( queueMessage, [callback] )

Updates the message in CloudQueue object.

Argument
queueMessage
string The message that you want to add to the Queue.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
queue.updateMessage("New Message String",{ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.getMessage( [count], [callback] )

Gets the message from CloudQueue object.

Gets the first message if count is not defined, else returns the number of messages according to count.

Argument
count
Number [optional] Describes the no of messages to get.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the data in a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.getMessage(3,{ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.getAllMessages( [callback] )

Get's all the message from CloudQueue.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//creat a queue queue.getAllMessages({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.getMessageById( id, [callback] )

Get's the message from CloudQueue according to its id.

Argument
id
string The id of the message you want to fetch.
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//creat a queue queue.getMessageById("message_id",{ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.get( [callback] )

Helps fetch the CloudQueue object.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//creat a queue queue.get({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.create( [callback] )

Creates a URL for the CloudQueue queue according to its name.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.create({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.addSubscriber( url, [callback] )

Adds subscribers to CloudQueue Object.

Argument
url
Object
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
url
Object
callback
Object [optional] if provided must have success and error functions to handle respective response.
//create a queue queue.addSubscriber(url, { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.removeSubscriber( url, [callback] )

Remove's the subscriber from CloudQueue Object.

Argument
url
Object
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.removeSubscriber(url, { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.peekMessage( count, [callback] )

Remove's the subscriber from CloudQueue Object.

Argument
count
Number The no of messages you want to fetch
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.peekMessage(3, { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.delete( [callback] )

Deletes the queue from server.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.delete({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.clear( [callback] )

Clears the Queue content

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.clear({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.refreshMessageTimeout( id, timeout, [callback] )

Helps you set timeout to refresh the queue at regular intervals.

Argument
id
string
timeout
string
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.refreshMessageTimeout(id, timeout, { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.deleteMessage( id, [callback] )

Deletes the message corresponding to the id provided.

Argument
id
String ID of the message you want to delete
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.deleteMessage("xxxx", { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.update( [callback] )

Updates the queue on the server.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.update({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.getAll( [callback] )

Gets all the queues with their respective messages from the server.

Argument
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.getAll({ success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.get( queueName, [callback] )

Get details of the Queue corresponding to given QueueName.

Argument
queueName
String Name of the queue which you want to fetch
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.get("myQueue", { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.delete( queueName, [callback] )

Deletes the queue from the server.

Argument
queueName
String Name of the queue which you want to fetch
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.delete("myQueue", { success: function(messages){ //success }, error: function(err){ //error } });
 

CloudQueue.QueueMessage( data )

Helps you create a Queue Message Object.

Argument
data
String Data which you want to store in Queue.
Returns
It returns the contents of a CloudQueue object if the operation is successful otherwise returns an error object along with JQuery promise (if callback is not provided).
//create a queue queue.QueueMessage("message_data");
 

CB.Column

This API allow to create a column object.

 

CB.Column(columnName, dataType, [required], [unique])

Initialize a column.
List of valid Data Type is given below.
Reqiure is a boolean that indicate whether the field can be null or not.
Unique field is a boolean type, indicates whether should contains unique value or not.

Arguments
columnName
String Column Name should not start with a number and should not contain any spaces and special characters.
dataType
Cloud Data TypesDefault data type is Text
required
Boolean Default value is False.
unique
Boolean Default value is False.
Returns

A cloudcolumn object

var column1 = new CB.Column('name', 'Text', true, false); var column2 = new CB.Column('uniqueId'); column2.dataType = 'Number'; column2.unique = true; column2.required = true; var table = new CB.CloudTable('Employee'); table.addColumn(column1); table.addColumn(column2); table.save().then(function(obj){ //cloud table object }, function(err){ //error });
 

Data Types

List of Valid Data Types

  • Text
  • Number
  • Email
  • URL
  • Boolean
  • DateTime
  • GeoPoint
  • File
  • List
  • Relation
  • Object

data types are case sensitive

If you are using Relation as a data type then you need to set relatedTo property to column object .
Valid relatedTo data types for Relation is CloudTable Object i.e. just set the table name in relatedTo property.

If you are using List as a data type then you need to set relatedTo property to column object .
Valid relatedTo data types for List are:
['CloudTable Objects', 'Text', 'Email', 'URL', 'Number', 'Boolean', 'DateTime', 'Boolean', 'GeoPoint', 'File', 'Object']

var column3 = new CB.Column('department', 'Relation'); column3.relatedTo = 'DepartmentTable'; var column4 = new CB.Column('skills', 'List'); column4.relatedTo = 'Text'; var table = new CB.CloudTable('Employee'); table.addColumn(column3); table.addColumn(column4); table.save().then(function(obj){ //cloud table object }, function(err){ //error });
 

Required

Used to set a column as required.

var column3 = new CB.Column('department',); column3.required = true;
 

Unique

Used to set a column as unique.

var column3 = new CB.Column('department',); column3.unique = true;
 

CB.CloudTable

This API allows to create, delete, get details of a table from an App by using master-key.

 

CB.CloudTable(tableName)

All the tables are in CloudBoost is a type of CloudTable. Pass the table name as a parameter to initialize a CloudTable.

Arguments
tableName
String Table should not start with a number and should not contain any spaces and special characters.
Returns

A CloudTable object

var table = new CB.CloudTable("TableName");
 

CloudTable.get(CloudTable, [callback])

To get a table's detail of an App use get method.

Arguments
cloudtable
CloudTable Object Pass a CloudTable Object
or
CloudTable Pass a Name of CloudTable
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

A CloudTable Object

var obj = new CB.CloudTable('Address'); CB.CloudTable.get(obj).then(function(table){ //Get CloudTable Object for requested table. }, function(err){ //get error details });
 

CloudTable.getAll([callback])

It fetch all tables of an App.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

Array of CloudTable object

CB.CloudTable.getAll().then(function(tableArray){ //get array of CloudTables }, function(err){ //get error details });
 

CloudTable.addColumn(columnObj)

Add a column to a table. go through Column to get more detail about how to initialize a column object.

Arguments
Column
Column ObjectCreate a Column object using Column Class and put this object as an Argument
or
Column NamePass the Column Name as the Argument
Returns

Void

var table = new CB.CloudTable('Student'); var column = new CB.Column('Name', 'Text'); table.addColumn(column); table.save().then(function(obj){ //new table object with new column }, function(err){ });
 

CloudTable.deleteColumn(columnObj)

Delete a column of a Table. go through Column to get more detail about how to initialize a Column Object.

Arguments
Column
Column ObjectCreate a column object using Column Class and put this object as an argument
or
Column NamePass the Column Name as the Argument
Returns

Void

var column = new CB.Column('Name', 'Text'); table.deleteColumn(column); table.save().then(function(obj){ //updated table object without 'Name' column }, function(err){ });
 

CloudTable.save([callback])

Save a CloudTable Object. It will automatically create all default columns for a table. If you want to create a user table or role table then just pass 'User' or 'Role' as an argument while creating cloudtable object.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

CloudTable Object

var table = new CB.CloudTable('NewTable'); table.save().then(function(obj){ //saved cloudtable object }, function(err){ });
 

CloudTable.delete([callback])

Delete a CloudTable object i.e. delete a table of an App.

Arguments
callback
Object [optional] if provided must have success and error functions to handle respective response.
Returns

Success or Error Status

var table = new CB.CloudTable('Student'); table.delete().then(function(status){ //success status },function(){ //get error status });
 

CloudTable.getColumn(column)

Get's the column object.

Arguments
column
String Name of the Column.
Returns

Cloud Column Object

var table = new CB.CloudTable('Student'); var acl = table.getColumn('ACL'); //gets the ACL column
 

CloudTable.updateColumn(Column)

Updated the CloudTable column to the column passed in.

Arguments
column
Object Column object.
Returns

void

var table = new CB.CloudTable('Student'); var name = new CB.Column('name'); name.unique = true; table.updateColumn(name); //updated the existing column name to new Column
 

CB.ACL

Each CloudObject namespace has security option by default. By default every object can be read and modified by anyone so for each object change the security option as desidred. For any object, you can specify which users/roles are allowed to read the object, and which users/roles are allowed to modify an object. To support this type of security, each object has an access control list, implemented by the CB.ACL class.

For each object CB.ACL object is a property in CloudObject.ACL class.

All the modifications in the ACL can be reflected only after the object is saved after the changes.

 

Constructor

Instantiates an ACL object.

Argument

It takes no argument

Returns

It returns nothing. It is called using a variable of which various parameters are set.

var obj = new CB.CloudObject('Student'); obj.ACL = new CB.ACL();
 

ACL.setPublicWriteAccess( value )

To allow/disallow public to write on a particular CloudObject

Argument
value
boolean
Returns

void

var obj = new CB.CloudObject("Student"); obj.ACL = new CB.ACL(); obj.ACL.setPublicWriteAccess(false); obj.save({ success: function(obj) { //Saving successfull }, error: function(err) { //Error occured in saving the object } });
 

ACL.setPublicReadAccess( value )

To allow/disallow public to read a particular object

Argument
value
boolean
Returns

void

var obj = new CB.CloudObject("Student"); obj.ACL = new CB.ACL(); obj.ACL.setPublicReadAccess(false); obj.save({ success: function(obj) { //Saving successfull }, error: function(err) { //Error occured in saving the object } });
 

ACL.setUserWriteAccess( userId, value )

To allow/disallow user having to write on a particular object.

Argument
userId
string The User ID of the user you want to set the access for
value
boolean
Returns

void

var obj = new CB.CloudObject("Student"); obj.ACL = new CB.ACL(); obj.ACL.setUserWriteAccess('idOfTheUser',true); obj.save({ success: function(obj) { //Saving successfull }, error: function(err) { //Error occured in saving the object } });
 

ACL.setUserReadAccess( userId, value )

To allow/disallow user having _id userId to read a particular object.

Argument
userId
string The user ID of the user you want to set the access for
value
boolean
Returns

It returns nothing.

var obj = new CB.CloudObject("Student"); obj.ACL = new CB.ACL(); obj.ACL.setUserReadAccess('idOfTheUser',true); obj.save({ success: function(obj) { //Saving successfull }, error: function(err) { //Error occured in saving the object } });
 

ACL.setRoleWriteAccess( roleId, value )

To allow/disallow users of roles roleId to write on a particular object

Argument
roleId
string The role ID of the Role you want to set the access for
value
boolean
Returns

void

var obj = new CB.CloudObject("Student"); obj.ACL.setRoleWriteAccess('roleId', true); obj.save({ success: function(obj) { //Saving successfull }, error: function(err) { //Error occured in saving the object } });
 

ACL.setRoleReadAccess( roleId, value )

To allow/disallow users of roles roleId to read a particular object

Argument
roleId
string The role ID of the Role you want to set the access for
value
boolean
Returns

void

var obj = new CB.CloudObject("Student"); obj.ACL.setWriteAccess('roleId', true); obj.save({ success: function(obj) { //Saving successfull }, error: function(err) { //Error occured in saving the object } });
 

JSON

Here's a way to serialize and de-serialize CloudBoost objects for passing it between your server and clients.

 

CB.toJSON( data )

Convert CloudBoost Object to JSON

Arguments
data
Any CloudBoost Object / Array of CloudBoost Objects
Returns

Serialized JSON

var obj = new CB.CloudObject('Sample'); CB.toJSON(obj);
 

CB.fromJSON( json )

Convert JSON to CloudBoost Objects

Arguments
data
JSON to convert it to CloudBoost Object
Returns

Serialized JSON

CB.fromJSON({/*Serialized JSON*/});
 

Contribute

We heart contributors. Love what we do and want to contribute?
JavaScript SDK : GitHub Repository

Our documentation is open source too!

Documentation : GitHub Repository

01001101 01100001 01100100 01100101 01110111 01101001 01110100 01101000 00111100 00110011