do something in 5 with gas 2-graduate to a database

14
do something useful with Apps Script in 5 minutes 2.Graduate to a database Bruce McPherson www.mcpher.com

Upload: bruce-mcpherson

Post on 18-Dec-2014

533 views

Category:

Technology


3 download

DESCRIPTION

Here's how to migrate your backend Google Apps Script spreadsheet to a parse.com database in a few minutes.

TRANSCRIPT

Page 1: Do something in 5 with gas 2-graduate to a database

do something useful with Apps Script in 5 minutes

2.Graduate to a databaseBruce McPhersonwww.mcpher.com

Page 3: Do something in 5 with gas 2-graduate to a database

Add libraries to script

create a scriptOpen resourcesAdd references to librariesMrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j

MHfCjPQlweartW45xYs6hFai_d-phDA33

Mhr42c9etIE-fQb2D9pwW0ai_d-phDA33

Page 4: Do something in 5 with gas 2-graduate to a database

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

Page 5: Do something in 5 with gas 2-graduate to a database

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'

}));

}

Page 6: Do something in 5 with gas 2-graduate to a database

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

}

Page 7: Do something in 5 with gas 2-graduate to a database

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';

Page 8: Do something in 5 with gas 2-graduate to a database

Get all the data

// get all the data

var result = handler.query();

if (result.handleCode < 0) throw result.handleError;

Page 9: Do something in 5 with gas 2-graduate to a database

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';

Page 10: Do something in 5 with gas 2-graduate to a database

Delete any parse.com data

// delete any data already there

var parseResult = parseHandler.remove();

if (parseResult.handleCode < 0) throw parseResult.handleError;

Page 11: Do something in 5 with gas 2-graduate to a database

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

Page 12: Do something in 5 with gas 2-graduate to a database

Check the counts match

// check count against original

if (parseHandler.count().data[0].count !== handler.count().data[0].count) throw 'oops'

Page 13: Do something in 5 with gas 2-graduate to a database

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"))

});