As you will know by now, ScriptDB is now deprecated. A year or so ago, I published some articles on alternatives to ScriptDB on the desktop liberation site, one of which was Parse.com. This has turned out to be one of the most popular topics, and one which I get a lot of questions of about.
I don’t do many posts on this blog anymore, see this post for why, but I thought I may as well use this, the 200th post, to summarize the status of the parse.com API shared library for Google Apps Script, and quickly show how to get your data from scriptDB to Parse.com.
There are 2 methods of using this library from Google Apps Script.
- Directly, where you would be sure that parse.com is the backend you would want to use
- Through a database abstraction library, which provides standardized access to a growing number of backend databases
function migratingFromScriptDb() { var tableName = 'VBAParseCustomers'; var enums = cDataHandler.dhConstants.DB; var userStore = PropertiesService.getUserProperties(); // get the data from scriptDB - i have a scriptDB driver, so Im using that. // you may want to read all your scriptDB data some other way to get your objects into an array. var dbHandler = new cDataHandler.DataHandler (tableName,enums.SCRIPTDB,undefined,'mydb',ScriptDb.getMyDb()); var theResult = dbHandler.query (); if (theResult.handleCode <0) throw (JSON.stringify(theResult)); var theData = theResult.data; // to parse.com - good choice for all deleteAndCopy ( theData , tableName,"mp", enums.PARSE, JSON.parse(userStore.getProperty("parseKeys"))); } function deleteAndCopy (data,tableName, id , type , ob ) { // get a handler var handler = new cDataHandler.DataHandler (tableName,type,undefined,id,ob); // delete existing data var result = handler.remove(); if (result.handleCode <0) throw (JSON.stringify(result)); // save the new data var result = handler.save(data); if (result.handleCode <0) throw (JSON.stringify(result)); return handler; }
function deleteAndCopyDirect (data,tableName, id , type , ob ) { // get a handler var userStore = PropertiesService.getUserProperties(); var parseCom = cParseCom.getParsed(tableName,JSON.parse(userStore.getProperty("parseKeys"))); // delete everything var w = parseCom.deleteObjects().flush(); if (!w.isOk()) { throw ("failed to delete objects:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } // write new stuff parseCom.batch(true); data.forEach(function(d) { parseCom.createObject(d); }); var w = parseCom.flush().batch(false); if (!w.isOk()) { throw ("failed to create objects:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } }