Asynchronous vs Simple

Asynchronous (async) data processes call a wider array of functions than simple processes. You can draw data from multiple independent sources using an async process, and even bring the project elements from one project into another programatically. 

This is a basic async example that gets the results from one data table and returns it unchanged.

Protobi.get_table("main", function(err, rows) {

return callback(null, rows) })


Within the async function, you can operate on rows as you would in a simple data process.

Protobi.get_table("main", function(err, rows) {  
    
    rows.forEach(function(row) {
    // do something for each row...
    })

  return callback(null, rows) })


Async functions

Asynchronous data processes can access the following utility functions:

Protobi.get_table( key, function(err, rows) { ... })

Gets data from a data table or process within this project.  The callback function contains a value rows which is an array of row objects representing the table data.  If an error occurs, err will have a truthy value.

Protobi.get_table( datasetId, key, function(err, rows) { ... })

Gets data from a data table or process within project represented by datasetId.  The callback function contains a value rows which is an array of row objects representing the table data.  

Protobi.get_tables( [keys], function(err, data) { ... })

Gets data from multiple tables or process within this project.  The callback function contains a value rows which is a a hash object with keys corresponding to each data table.

Protobi.get_table( datasetId, [keys], function(err, data) { ... })

Gets data from multiple tables or process within project represented by datasetId.  The callback function contains a value rows which is a a hash object with keys corresponding to each data table.

Protobi.set_table( key, rows, filename, function(err, rows) { ... })

Saves an array of row values as a data table to this project, with a given filename. This allows you to save data to one or more existing or new data tables.  If key is equal to the key for the process itself, this is akin to calling callback(err, rows) .

Protobi.set_table( datasetId, key, filename,  function(err, rows) { ... })

Saves an array of row values as a data table to another project specified by datasetId, with a given filename.   If datasetId and key are equal to the datasetId and key for the process itself, this is akin to calling callback(err, rows) .

Protobi.get_elements( function(err, tabular) { ... })

Returns elements configuration for this project as a collection of live element objects. See the Protobi JSON API for more details.

Protobi.get_elements( datasetId, function(err, tabular) { ... })

Returns elements configuration for a specified project as a collection of live element objects. See the Protobi JSON API for more details.

Protobi.left_join( left, right, [keys], [keeps])

Merge two arrays of row objects, left and right, using columns keys  as merge keys, and retaining specified keep columns from the right table.  This assumes keys have the same names in the left and right tables, and keeps have retain the same names in the right table and result.  This returns a new array of row objects and does change the inputs.

Protobi.left_join( left, right, {keys}, {keeps})

Merge two arrays of row objects, left and right, using columns in keys  as merge keys, and retaining specified keep columns from the right table.  The hash structure allows you to refer to different column names for merge keys in the left and right table and change column names when retaining them from the right table into the results.  This returns a new array of row objects and does change the inputs.

Global objects

Data processes can also access a number of global libraries:

  • d3 (d3js.com)     Diverse collection of data utilities
  • _ (lodash.com)   Diverse collection of common utility functions
  • moment (momentjs.com)   Advanced date processing functions


Advanced support

Protobi can handle complex data processing cases, not limited to those that are documented within our tutorials. Our support team is ready to help you with your specific goals. Please contact us at support@protobi.com to discuss further.