SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
do something useful with
Apps Script in 5 minutes
8. Copy between databases
Bruce McPherson
www.mcpher.com
Snippet objectives
● Open a database using dbabstraction
● Copy to another couple of formats
Libraries used
● database abstraction
● driver sheet
● driver mongoLab
● driver drive
Add libraries to script
● get the id of the sheet you want to copy
● create a script
● open resources
● add references to libraries
MHfCjPQlweartW45xYs6hFai_d-phDA33
Mrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j
MPAHw_-cHNDxsYAg263J7Fai_d-phDA33
create mongolab account
● If you havent already got a mongolab
account, sign up to a free plan https:
//mongolab.com
● Create a new free deployment
create mongolab api key
● Click on your username
● get an API key and enable data access
write mongo key to properties
● Write and execute one off script to store
mongolab restapikey to properties service
function oneTimeSet () {
PropertiesService.getUserProperties()
.setProperty("mongoLabKeys", JSON.stringify({
"restAPIKey":"h3xxxxxxcz"
}));
}
layout what you are going to do
function copyTheSheet () {
// open the sheet to be copied
// get all the data
// open the database to copy it to
// write it
// check it
}
My test data looks like this
Sheet name is 'customers'
open the sheet to be copied
● use the ID and Sheet name to open.
// open the sheet to be copied
var sheetHandler = cDbAbstraction.DbAbstraction(cDriverSheet, {
dbid:"1EhgZ1-q9tP1u9BSEQPIQiSGozdfjsHn3zB1JfQGbftw",
siloid:"customers"
});
if (!sheetHandler.isHappy()) throw 'could not open sheet';
Get the data on the sheet
● a query with no arguments gets all the data
// get all the data
var result = sheetHandler.query();
if (result.handleCode < 0) throw JSON.stringify(result);
Get handle for mongolab database
● will use a collection called 'customers' in the
database 'dosomethinginfive'
var dbHandler = cDbAbstraction.DbAbstraction(cDriverMongoLab, {
dbid:"dosomethinginfive",
siloid:"customers",
driverob:JSON.parse(PropertiesService.getUserProperties()
.getProperty("mongoLabKeys"))
});
if (!dbHandler.isHappy()) throw 'could not open database';
delete any existing data
● delete all the current data in the db table
// delete any data already there
var dbResult = dbHandler.remove();
if (dbResult.handleCode < 0) throw JSON.stringify(dbResult);
copy the data from the sheet
● copy the data from the sheet
// write it all
var dbResult = dbHandler.save (result.data);
if (dbResult.handleCode < 0) throw JSON.stringify(dbResult);
check all was written
● do a count query on what was written
// check that it was all written
var dbResult = dbHandler.count ();
if (dbResult.data[0].count !== result.data.length)
throw 'data counts dont match';
look at data on mongolab
Homework
Do the same thing, but copy to a Drive file
instead of MongoLab.
Hints.
● You'll need cDriverDrive (Ma__4vH--nQ_FPsuNF1BFuyz3TLx7pV4j)
● There is only one line different from the mongolab version (specify the folder and file name)
// open the database to copy it to
var dbHandler = cDbAbstraction.DbAbstraction(cDriverDrive, {
dbid:"/datahandler/driverdrive/tasks",
siloid:"customers.json"
});
Follow up materials
Take a copy of these slides
Join me on G+, or the G+ community
More on desktop liberation
More on database abstraction
More 5 minute things

Weitere Àhnliche Inhalte

Was ist angesagt?

VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primerBruce McPherson
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email logBruce McPherson
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed versionBruce McPherson
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelBruce McPherson
 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introductionStefan Pettersson
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionBruce McPherson
 
Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014Evgeny Nikitin
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodbLee Theobald
 
HeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientHeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientDimitar Ivanov
 
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to RedisMongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to RedisJason Terpko
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deploymentsOdoo
 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsBartosz Konieczny
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialJason Terpko
 
Fetch data from form
Fetch data from formFetch data from form
Fetch data from formShahriar Malik
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingJason Terpko
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkRde:code 2017
 

Was ist angesagt? (20)

VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
Goa tutorial
Goa tutorialGoa tutorial
Goa tutorial
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email log
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
Dbabstraction
DbabstractionDbabstraction
Dbabstraction
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and Excel
 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introduction
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
 
Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014Lazy evaluation drupal camp moscow 2014
Lazy evaluation drupal camp moscow 2014
 
Introduction tomongodb
Introduction tomongodbIntroduction tomongodb
Introduction tomongodb
 
HeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP ClientHeadCouch - CouchDB PHP Client
HeadCouch - CouchDB PHP Client
 
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to RedisMongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasets
 
MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster Tutorial
 
Fetch data from form
Fetch data from formFetch data from form
Fetch data from form
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and Merging
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
 
Unqlite
UnqliteUnqlite
Unqlite
 

Ähnlich wie Do something in 5 with gas 8-copy between databases

MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?Binary Studio
 
Data Abstraction for Large Web Applications
Data Abstraction for Large Web ApplicationsData Abstraction for Large Web Applications
Data Abstraction for Large Web Applicationsbrandonsavage
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine ProjectDaniel Lima
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011camp_drupal_ua
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & IntroductionJerwin Roy
 
introtomongodb
introtomongodbintrotomongodb
introtomongodbsaikiran
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
XPages Blast - ILUG 2010
XPages Blast - ILUG 2010XPages Blast - ILUG 2010
XPages Blast - ILUG 2010Tim Clark
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausWomen in Technology Poland
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-DrupalForest Mars
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbMongoDB APAC
 
Architecting Wide-ranging Analytical Solutions with MongoDB
Architecting Wide-ranging Analytical Solutions with MongoDBArchitecting Wide-ranging Analytical Solutions with MongoDB
Architecting Wide-ranging Analytical Solutions with MongoDBMatthew Kalan
 
Drupal 7 database api
Drupal 7 database api Drupal 7 database api
Drupal 7 database api Andrii Podanenko
 
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptxsukrithlal008
 

Ähnlich wie Do something in 5 with gas 8-copy between databases (20)

MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?
 
Data Abstraction for Large Web Applications
Data Abstraction for Large Web ApplicationsData Abstraction for Large Web Applications
Data Abstraction for Large Web Applications
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine Project
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
introtomongodb
introtomongodbintrotomongodb
introtomongodb
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
MongoDB
MongoDBMongoDB
MongoDB
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
XPages Blast - ILUG 2010
XPages Blast - ILUG 2010XPages Blast - ILUG 2010
XPages Blast - ILUG 2010
 
MongoDB Basics Unileon
MongoDB Basics UnileonMongoDB Basics Unileon
MongoDB Basics Unileon
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
 
MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
 
Architecting Wide-ranging Analytical Solutions with MongoDB
Architecting Wide-ranging Analytical Solutions with MongoDBArchitecting Wide-ranging Analytical Solutions with MongoDB
Architecting Wide-ranging Analytical Solutions with MongoDB
 
Drupal 7 database api
Drupal 7 database api Drupal 7 database api
Drupal 7 database api
 
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx171_74_216_Module_5-Non_relational_database_-mongodb.pptx
171_74_216_Module_5-Non_relational_database_-mongodb.pptx
 

KĂŒrzlich hochgeladen

Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...shivangimorya083
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptDr. Soumendra Kumar Patra
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Call Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girl
Call Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girlCall Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girl
Call Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girlkumarajju5765
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 

KĂŒrzlich hochgeladen (20)

Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔Body to body massage wit...
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Call Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girl
Call Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girlCall Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girl
Call Girls đŸ«€ Dwarka âžĄïž 9711199171 âžĄïž Delhi đŸ«Š Two shot with one girl
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 

Do something in 5 with gas 8-copy between databases

  • 1. do something useful with Apps Script in 5 minutes 8. Copy between databases Bruce McPherson www.mcpher.com
  • 2. Snippet objectives ● Open a database using dbabstraction ● Copy to another couple of formats Libraries used ● database abstraction ● driver sheet ● driver mongoLab ● driver drive
  • 3. Add libraries to script ● get the id of the sheet you want to copy ● create a script ● open resources ● add references to libraries MHfCjPQlweartW45xYs6hFai_d-phDA33 Mrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j MPAHw_-cHNDxsYAg263J7Fai_d-phDA33
  • 4. create mongolab account ● If you havent already got a mongolab account, sign up to a free plan https: //mongolab.com ● Create a new free deployment
  • 5. create mongolab api key ● Click on your username ● get an API key and enable data access
  • 6. write mongo key to properties ● Write and execute one off script to store mongolab restapikey to properties service function oneTimeSet () { PropertiesService.getUserProperties() .setProperty("mongoLabKeys", JSON.stringify({ "restAPIKey":"h3xxxxxxcz" })); }
  • 7. layout what you are going to do function copyTheSheet () { // open the sheet to be copied // get all the data // open the database to copy it to // write it // check it }
  • 8. My test data looks like this Sheet name is 'customers'
  • 9. open the sheet to be copied ● use the ID and Sheet name to open. // open the sheet to be copied var sheetHandler = cDbAbstraction.DbAbstraction(cDriverSheet, { dbid:"1EhgZ1-q9tP1u9BSEQPIQiSGozdfjsHn3zB1JfQGbftw", siloid:"customers" }); if (!sheetHandler.isHappy()) throw 'could not open sheet';
  • 10. Get the data on the sheet ● a query with no arguments gets all the data // get all the data var result = sheetHandler.query(); if (result.handleCode < 0) throw JSON.stringify(result);
  • 11. Get handle for mongolab database ● will use a collection called 'customers' in the database 'dosomethinginfive' var dbHandler = cDbAbstraction.DbAbstraction(cDriverMongoLab, { dbid:"dosomethinginfive", siloid:"customers", driverob:JSON.parse(PropertiesService.getUserProperties() .getProperty("mongoLabKeys")) }); if (!dbHandler.isHappy()) throw 'could not open database';
  • 12. delete any existing data ● delete all the current data in the db table // delete any data already there var dbResult = dbHandler.remove(); if (dbResult.handleCode < 0) throw JSON.stringify(dbResult);
  • 13. copy the data from the sheet ● copy the data from the sheet // write it all var dbResult = dbHandler.save (result.data); if (dbResult.handleCode < 0) throw JSON.stringify(dbResult);
  • 14. check all was written ● do a count query on what was written // check that it was all written var dbResult = dbHandler.count (); if (dbResult.data[0].count !== result.data.length) throw 'data counts dont match';
  • 15. look at data on mongolab
  • 16. Homework Do the same thing, but copy to a Drive file instead of MongoLab. Hints. ● You'll need cDriverDrive (Ma__4vH--nQ_FPsuNF1BFuyz3TLx7pV4j) ● There is only one line different from the mongolab version (specify the folder and file name) // open the database to copy it to var dbHandler = cDbAbstraction.DbAbstraction(cDriverDrive, { dbid:"/datahandler/driverdrive/tasks", siloid:"customers.json" });
  • 17. Follow up materials Take a copy of these slides Join me on G+, or the G+ community More on desktop liberation More on database abstraction More 5 minute things