Parse.com – with
GAS
HOW TO USE A CLOUD BASED NOSQL DATABASE WITH
GOOGLE APPS SCRIPT

EXCEL LIBERATION
What is parse.com?
A noSQL database
SDK for multiple platforms, including IOS and Android
Cloud based script execution
Bui...
Why use parse.com with GAS?
Google Apps Script already has its own noSQL database – scriptDB – fine for staying inside GAS...
Authentication using GAS API
Once only per user

Encrypt parse.com
restAPI and
application ID Keys

Store in User
Properti...
Code for Authentication
First time to register and encrypt credentials for this user

A Parse Class is
like a Table

funct...
Code for a Query

Queries are by
example. Default
is to get all objects
in the class

function testparsequery () {
// get ...
Get by objectID
Each parse object
function testGetItemByUniqueId () {
(like a row) gets
// get a handle for this class
ass...
JSON.stringifiable object is returned
from every operation
{
"address":"584-5478 Et Road",
"city":"Hastings",
"company":"E...
Deleting objects
getParsed(‘a parse class’).batch().deleteObjects()

Or just some
getParsed(‘aclass’).batch().deleteObject...
Creating objects
getParsed(“aclass”).batch().createObject(job)

Delete first, if you don’t want a new object to be created...
Updating objects
function testparseUpdate () {
// get some items by query and change the scheme name to something else
var...
Counting objects in a class
Logger.log (getParsed("VBAParseCustomers").count({country:"Libya"}));

Or total in class
Logge...
Copying a sheet to a parse class
// copy two sheets to parse.com
function testPopulate() {
populateFromName ("gasParseCust...
Typical setup
Reference your
parseCom library in
each of your scripts
Your scripts

Your
spreadsheets

UserProperties
Your...
Getting started
Register with parse.com, create an application and get an applicationID and a restAPI key
Set up your pars...
Upcoming SlideShare
Loading in...5
×

parse.com - how to use a noSQL data base for Google Apps Script

2,076

Published on

From Excel Liberation, here's free shared Google Apps Scripts that provides a wrapper for the parse.com noSQL rest API. Using a cloud based database means that you can now share data between Excel and other platforms such as Android and IOS.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,076
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

parse.com - how to use a noSQL data base for Google Apps Script

  1. 1. Parse.com – with GAS HOW TO USE A CLOUD BASED NOSQL DATABASE WITH GOOGLE APPS SCRIPT EXCEL LIBERATION
  2. 2. What is parse.com? A noSQL database SDK for multiple platforms, including IOS and Android Cloud based script execution Built in analytics and dashboards Role based security Free for most of us Easy to use and to get started with Best for smaller datasets Read more at parse.com
  3. 3. Why use parse.com with GAS? Google Apps Script already has its own noSQL database – scriptDB – fine for staying inside GAS Using Parse allows GAS to easily share data with other platforms and across workbooks Is easier to get started with than many other noSQL databases There is a restAPI that’s pretty easy to implement a GAS wrapper class for There’s already a Parse VBA API – this one is virtually the same. You can write code in one and copy to the other with only minor language syntax changes. You can use oAuth2 if you want, but this also adds parse.com authentication Parse.com is more table like in structure. ScriptDB is more free form. Both approaches have advantages Because we can
  4. 4. Authentication using GAS API Once only per user Encrypt parse.com restAPI and application ID Keys Store in User Properties If you want you can add oAuth2 to further control access Subsequent accesses from any Google Apps Script Get from User Properties Decrypt restAPI and application ID keys Avoids the problem of needing keys in every Script Access Parse.com
  5. 5. Code for Authentication First time to register and encrypt credentials for this user A Parse Class is like a Table function firstTimeParseCom () { // run this once for each user/scope combination parseCom.setRegistryPackage ( "parse","default",{restAPIKey: "your rest API key", applicationID:"your application id"}); } Thereafter from any script executed as this user var parseCom = getParsed("VBAParseCustomers");
  6. 6. Code for a Query Queries are by example. Default is to get all objects in the class function testparsequery () { // get a number of items that match a query by example var w = getParsed("VBAParseData").getObjectsByQuery( {customerid:1},{order:'-value'}); //test if it worked, and do something with the results if (w.isOk() ){ Logger.log( "all is ok"+ JSON.stringify(w.jObject())); } else { throw( "failed to do query:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } } All methods are chainable JSON.stringify(getParsed("VBAParseData").getObjectsByQuery( {customerid:1},{order:'-value'}).jObject()); Or as a one liner
  7. 7. Get by objectID Each parse object function testGetItemByUniqueId () { (like a row) gets // get a handle for this class assigned a unique var parseCom = getParsed("VBAParseCustomers"); // use a valid unique ID to get the data ID if (parseCom.getObjectById("VbzHLEte62").isOk()) { Logger.log (JSON.stringify(parseCom.jObject())); } else { throw ("failed to get object:" + parseCom.browser().url() + ":" + parseCom.browser().status() + ":" + parseCom.browser().text()); } } All methods are Or as a one liner chainable JSON.stringify(getParsed("VBAParseCustomers").getObjectById(("VbzHLEte62").jObject());
  8. 8. JSON.stringifiable object is returned from every operation { "address":"584-5478 Et Road", "city":"Hastings", "company":"Eu Accumsan Sed Inc.", "coordinates":"38.2264, 75.04849", "country":"Comoros", "customerid":100, "email":"tincidunt.nibh@Curabitur.net", "name":"Contreras", "region":"NI", "zip":"12396", "createdAt":"2013-11-26T14:36:40.517Z", "updatedAt":"2013-11-26T14:36:40.517Z", "objectId":"SmnyjZKs9m" } Results are in the .jObect property of cParseCom
  9. 9. Deleting objects getParsed(‘a parse class’).batch().deleteObjects() Or just some getParsed(‘aclass’).batch().deleteObjects( {customerID:1}); .deleteObjects will delete all objects (rows) that match its query. Delete operations can be ‘batched’
  10. 10. Creating objects getParsed(“aclass”).batch().createObject(job) Delete first, if you don’t want a new object to be created getParsed(“aclass”). getObjectsByQuery(job).batch().delete().createObject(job) .createObjects will create a new class if it doesn’t exist Create operations can be ‘batched’
  11. 11. Updating objects function testparseUpdate () { // get some items by query and change the scheme name to something else var w = getParsed("VBAParseData").batch(true).updateObjects({customerid:39}, {customerid:1}).batch(false); if (w.isOk() ){ Logger.log( "all is ok"+ JSON.stringify(w.jObject())); } else { throw( "failed to do query:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } } Or as a one liner .createObjects will create a new class if it doesn’t exist Update operations can be ‘batched’ JSON.stringify(getParsed("VBAParseData").batch(true).updateObjects({customerid:39}, {customerid:1}).batch(false).jObject());
  12. 12. Counting objects in a class Logger.log (getParsed("VBAParseCustomers").count({country:"Libya"})); Or total in class Logger.log (getParsed("VBAParseData").count()); .count() will return the total number of records in the class or that match a query if one is given
  13. 13. Copying a sheet to a parse class // copy two sheets to parse.com function testPopulate() { populateFromName ("gasParseCustomers"); populateFromName ("gasParseData"); } Code for populateFromName function populateFromName (sheetName) { parseCom.populateFromSheetValues(SpreadsheetApp.getActiveSpreadsheet() .getSheetByName(sheetName).getDataRange().getValues(), sheetName); } Call shared scripts from a workbook with the data
  14. 14. Typical setup Reference your parseCom library in each of your scripts Your scripts Your spreadsheets UserProperties Your encrypted parse.com credentials are stored here Create your own parseCom library – shared in between your scripts Copy parseCom library code from here cParseCom library – shared by everyone, owned by Excel Liberation Reference this project key in your parseCom library MMaKU0wHrNShUwFy pY3nM8iz3TLx7pV4j
  15. 15. Getting started Register with parse.com, create an application and get an applicationID and a restAPI key Set up your parseCom script with this code Add a reference to cParseCom at MMaKU0wHrNShUwFypY3nM8iz3TLx7pV4j Create a first time script, add a reference to your parseCom library and run this function firstTimeParseCom () { // run this once for each user/scope combination parseCom.setRegistryPackage ( "parse","default",{restAPIKey: "your rest API key", applicationID:"your application id"}); } Run some of the examples in parseCom Create some scripts that reference your parseCom library Get some testData (there’s some here), reference your parseCom, and load some data from Worksheets Read about how all this works and learn how to do more complex operations at Excel Liberation For help and more information visit me on GooglePlus, join our forum, follow the blog or follow me on twitter .
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×