Update Nov2017
UPDATE:  parse.com as now been closed and moved to parseplatform.org. I will update the content of this page an move the back-end to this platform

In parse.com – nosql database for VBA, I described how to use cParseCom to be able to use parse.com directly from VBA. You can find the implementation details here parse.com api class for VBA

Here’s a few examples – we’ll walk through the code shown below

The Code

Initial authentication

Before you can start, you need to get your own credentials from parse.com. It’s free and easy. As described in parse.com – nosql database for VBA, once you have those you should register yourself on this PC. You won’t need to run this again after the first time.
Afterwards we use getParsed(‘classname’), which looks like this.

Populate from a sheet – walkthrough

Getting credentials from the registry

Before we can do anything, we have to pick up the encrypted credentials we stored as a one off exercise. The should be one instance of cParseCom for every parse.com class – in this case I’m creating or updating a class with the same name as the sheet I’m importing .Adding .batch() will set this instance to batch Mode. That means that rest Queries will be automatically batched up as much as possible to minimize fetches.

Deleting objects

Since we are populating sheets, we want to empty out the current contents.  deleteObjects with no arguments will do that

Getting Data

We can use cDataSet (see How to use cDataSet) to minimize playing around with spreadsheet contents. It also has a useful property (.JObject) which returns a useful JSON friendly cJobject (see How to use cJobject), each child of which represents a worksheet row, already in the correct format for createObject() to create a row in the parse.com class database.

Clearing up

As with most classes on this site, cParseCom features a .tearDown function which ensures that any memory it is using gets cleaned up.  Since we using batch Mode, we have to flush, before exiting to clear any outstanding requests. Finally .count() will show how many rows are in the newly created table

Get an object by its unique ID – walkthrough

Each object (row) has a unique ID. Here’s how to get it (you’ll need to look at your parse.com dashboard to get a valid objectID for the data you’ve just loaded).
which, when you do this;
looks like this

Do a query- walkthrough

Queries in parse are by example. You can see the details here. You can set up any query by making a cJobject with the filters required. Here Im using JSONParse to create a jobject which will select all objects with customerid = 1.
Here’s the whole thing,
Which returns something that starts like this.

Counting objects – walkthrough

The .count() function will take the same arguments as getObjectsByQuery() and return the number of objects that match

Updating objects – walkthrough

The .updateObjects() function will take the same arguments as getObjectsByQuery() and return the  objects that match, and then update any fields in those objects mentioned in the second argument; so this updates the customerId for all objects belonging to customerId 39 form 39 to 1.
Here’s the whole thing. Note that I specify .batch() here. Updates, Creates and Deletes can, and should be batched for better performance. And when you batch, don’t forget to flush to commit the updates.

A small application – walkthrough

In this example, we’ll find any customers in United States, look up their orders, and print out some data about them.
We need 2 instances of cParseCom
Set up a query for US
Find Them
Look through each one
Do a query on their orders
Print out each of their orders

Here’s the whole thing

And the results
United States Hammond        85            161 
United States Nash           97            282 
United States Nash           97            391 

Get involved

See parse.com – nosql database for VBA for more on this topic
For help and more information join our forum, follow the blog or follow me on Twitter