do something in 5 with gas 2-graduate to a database
DESCRIPTION
Here's how to migrate your backend Google Apps Script spreadsheet to a parse.com database in a few minutes.TRANSCRIPT
do something useful with Apps Script in 5 minutes
2.Graduate to a databaseBruce McPhersonwww.mcpher.com
Snippet objectives
● Use the lessons learned in ‘using a spreadsheet as a database’
● Migrate data to a database - This example uses Parse.com
Libraries used● database abstraction● driver sheet● driver parse
Add libraries to script
create a scriptOpen resourcesAdd references to librariesMrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j
MHfCjPQlweartW45xYs6hFai_d-phDA33
Mhr42c9etIE-fQb2D9pwW0ai_d-phDA33
Sign up to Parse.com
● Sign up to parse.com● Create an application● Get api keysWe’re going to need the ● Application ID● REST API Key
Store keys in properties
We’ll use the script propertiesJust need to run this oncefunction storeMyKeys () {
PropertiesService.getScriptProperties().setProperty( "parseKeys", JSON.stringify ({
restAPIKey:'9oQAS9MO2fccccccccccccccccn4vp8',
applicationID:'kaIR5Tak4Ycccccccccczl1TgyO2'
}));
}
layout what you are going to dofunction myFunction() {
// open spreadsheet as database
// get all the data
// open parse.com database
// delete any data already there
// write the data
// check count against original
}
Get a handler for the sheethttps://docs.google.com/spreadsheets/d/14xvwnQwhvw4jSGRBo7ZbJvNaNu438-5mMl2u_TJswlw/edit?usp=sharing
// open spreadsheet as database
var handler = new cDbAbstraction.DbAbstraction (cDriverSheet, {
siloid:'carrierCodes',
dbid:'14xvwnQwhvw4jSGRBo7ZbJvNaNu438-5mMl2u_TJswlw',
});
if (!handler.isHappy()) throw 'unable to open sheet';
Get all the data
// get all the data
var result = handler.query();
if (result.handleCode < 0) throw result.handleError;
Get a handler for parse.com
// open parse.com database
var parseHandler = new cDbAbstraction.DbAbstraction (cDriverParse, {
siloid:'carrierCodes',
driverob:JSON.parse(
PropertiesService.getScriptProperties().getProperty("parseKeys"))
});
if (!parseHandler.isHappy()) throw 'unable to open parse.com';
Delete any parse.com data
// delete any data already there
var parseResult = parseHandler.remove();
if (parseResult.handleCode < 0) throw parseResult.handleError;
Migrate the data over from Sheet
// write the data
var parseResult = parseHandler.save(result.data);
if (parseResult.handleCode < 0) throw parseResult.handleError;
check it - using the parse.com dashboard
Check the counts match
// check count against original
if (parseHandler.count().data[0].count !== handler.count().data[0].count) throw 'oops'
Go and play on parse.comRepeat the examples in ‘using a spreadsheet as a database’The only difference is how you get a handler. // open spreadsheet as database
var handler = new cDbAbstraction.DbAbstraction (cDriverSheet, {
siloid:'carrierCodes',
dbid:'14xvwnQwhvw4jSGRBo7ZbJvNaNu438-5mMl2u_TJswlw',
});
// open parse.com database
var parseHandler = new cDbAbstraction.DbAbstraction (cDriverParse, {
siloid:'carrierCodes',
driverob:JSON.parse(
PropertiesService.getScriptProperties().getProperty("parseKeys"))
});
Follow up materials
Take a copy of this scriptTake a copy of the sheetTake a copy of these slidesJoin me on G+, or the G+ communityMore on desktop liberationMore on database abstraction