Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Do something in 5 minutes with gas 1-use spreadsheet as database

5,481 views

Published on

Here's one in a series of tutorials where you can do something useful from scratch in 5 minutes using Google Apps Script. This example shows how to use a Google Spreadsheet as a database

Published in: Software
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/39pMlLF ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Do something in 5 minutes with gas 1-use spreadsheet as database

  1. 1. do something useful with Apps Script in 5 minutes 1.Use a spreadsheet as a database Bruce McPherson www.mcpher.com
  2. 2. Snippet objectives ● Set up a spreadsheet for use as a database ● Demonstrate Read/write/delete updating Libraries used ● database abstraction ● driver sheet
  3. 3. Add libraries to script create a script Open resources Add references to libraries Mrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j MHfCjPQlweartW45xYs6hFai_d-phDA33
  4. 4. layout what you are going to do function myFunction() { // open spreadsheet as database // do a query // add a new record // do a query and sort and limit // delete added record // count query }
  5. 5. Get a handler for the sheet https://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';
  6. 6. 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}]
  7. 7. 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}]
  8. 8. 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}]
  9. 9. Follow up materials Take a copy of this script Take a copy of the sheet Take a copy of these slides Join me on G+, or the G+ community More on desktop liberation More on database abstraction

×