Datastore

The Turbo Datastore supports custom objects for all projects. A custom object is an entity that does not fall under the default classes the Turbo provides: User, Post, and Comment.

Creating Objects

To create a custom object, call the create(resourceName, params, completion) function from the Turbo SDK which takes a resource name argument, parameters JSON argument and a callback:

..assets/js/app.js

Entities Dashboard

All entites can be viewed, updated, and deleted on the entities dashboard for each project. To view the dashboard, log in to your Turbo 360 account and click on your project. From there, click the "entities" menu item on the left hand menu then click the dropdown menu which appears. Among the menu items should be your custom resource(s). Click on a custom resource to view all current entities under that category:

Click to enlarge

Fetching Objects

To fetch a specific entity by ID number, call the fetchOne(resourceName, id, completion) method:

  • resourceName: the name of the resource ('team')
  • id: the unique ID of the entity to fetch
  • completion: callback with 'err' and 'data' arguments

The 'data' argument in the callback will contain the entity fetched. If it is not found, the 'err' argument will be populated instead with corresponding message key.

..assets/js/app.js

Fetching multiple entities with a query filter is also supported by the datastore. To do so, use the fetch(resourceName, filters, completion) method:

  • resourceName: the name of the resource ('team')
  • filters: JSON object specifying query filters as key-value pairs. If null, all entities of resource will be returned.
  • completion: callback with 'err' and 'data' arguments

..assets/js/app.js

Note that if no entities are returned, the 'err' argument is NOT populated - the 'data' argument returns with an empty array.

Updating Objects

Updating objects is done through the update(resourceName, entity, params, completion) function. The arguments are as follows:

  • resourceName: the name of the resource ('team')
  • entity: the original entity being updated
  • params: a JSON object with updated fields - new fields can be added here.
  • completion: callback with 'err' and 'data' arguments

..assets/js/app.js

The update command above will add two new fields to the original team object: 'sport' and 'league'. Current fields can be changed as well through this method.

Deleting Objects

To delete an object, use the remove(resourceName, entity, completion) method.

  • resourceName: the name of the resource ('team')
  • entity: the entity being removed
  • completion: callback with 'err' and 'data' arguments

..assets/js/app.js

Contact

If you have any questions, comments or feedback, feel free to contact us at matthew@turbo360.co