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.
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
parse.com - how to use a noSQL data base for Google Apps Script
1. Parse.com – with
GAS
HOW TO USE A CLOUD BASED NOSQL DATABASE WITH
GOOGLE APPS SCRIPT
EXCEL LIBERATION
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. 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. 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. 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. 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. 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. 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. 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’
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. 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. 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. 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. 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 .