Do something in 5 minutes with gas 1-use spreadsheet as database
-
Upload
bruce-mcpherson -
Category
Software
-
view
1.662 -
download
3
description
Transcript of Do something in 5 minutes with gas 1-use spreadsheet as database
do something useful with Apps Script in 5 minutes1.Use a spreadsheet as a database
Bruce McPhersonwww.mcpher.com
Snippet objectives
● Set up a spreadsheet for use as a database● Demonstrate Read/write/delete updating
Libraries used● database abstraction● driver sheet
Add libraries to script
create a scriptOpen resourcesAdd references to librariesMrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j
MHfCjPQlweartW45xYs6hFai_d-phDA33
layout what you are going to dofunction myFunction() {
// open spreadsheet as database
// do a query
// add a new record
// do a query and sort and limit
// delete added record
// count query
}
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';
Do a query
// do a query
var result = handler.query ({carrier:'UA'});
if (result.handleCode < 0) throw result.handleError;
Logger.log(result.data);
result...
[{name=United Airlines, carrier=UA}]
Add something and query
// add a new record
var result = handler.save ({carrier:'xx',name:'Dodgy Air'});
if (result.handleCode < 0) throw result.handleError;
// do a query and sort and limit
var result = handler.query ({},{sort:'-carrier',limit:5});
if (result.handleCode < 0) throw result.handleError;
Logger.log(result.data);
result...
[{name=Dodgy Air, carrier=xx}, {name=Great Lakes Airlines, carrier=ZK}, {name=Great Lakes Airlines, carrier=ZK}, {name=Shenzhen Airlines, carrier=ZH}, {name=Monarch Airways, carrier=ZB}]
delete and count
// delete added record
var result = handler.remove ({name:'Dodgy Air'});
if (result.handleCode < 0) throw result.handleError;
// count query
var result = handler.count ();
if (result.handleCode < 0) throw result.handleError;
Logger.log(result.data);
result...
[{count=199.0}]
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