SlideShare a Scribd company logo
VBA API for
ScriptDB
Google Apps ScriptDB from Excel
what is this API for?

•
•
•
•

Allow maintenance and query Google Apps
Script ScriptDB directly from VBA
Share data in real time between Google
Docs and Office
a free noSQL database for Excel
Migration or coexistence path for GAS and
VBA
COMPONENTS
Your
ScriptDB
dispatcher
Your
Your
Your
code
code
VBA
code

PC
Registry

simple
noSql
VBA
API

encrypted
oauth2
credentials

oauth2 /
rest

Your
Your
code
Multiple
code
ScriptDB

Your GAS
webapp
Handler (s)
GAS
Library
API
authentication with oAuth2
One off
credential
storage

user/google
scope

Registry

● Get oAuth2 credentials from Google Cloud Console
● Run the below to encrypt them on your PC, one time
only.
getGoogled("drive", , "xxxxx.apps.googleusercontent.com", "xxxxx").tearDown

● Credentials are shared between all VBA APIs
needing oAuth2 on Excel Liberation
● Thereafter, oauth2 dance is automatically handled in
all API requests
optional access control
User and
Access
type
credentials
your entry/
your scope

Registry

● You can also optionally add a couple more keys,
which are passed with every request in its header
● Equivalent to the RESTAPIkey and ApplicationID in
parse.com
● Your Gas Webapp handler can inspect these to
signal the GAS API the type of access allowed
● Only needs to be stored one time
scriptdbCom.init("anything",”some entry id” ,”some scope id”,
"your app id", _
"your restapikey", , , True, _
"Gas web app url endpoint").tearDown
comparison with parse.com API
VBA and GAS Main Apps are virtually the same code irrespective of the
database

cParseCom
VBA API

cParseCom
GAS API

cScriptDBCom
VBA API

parse.com restAPI handler

GAS scriptDB
webApp and API
library

parse.com cloud based noSQL
database

GAS scriptDB
cloud based noSQL
database
optimization and batching
•
•
•

The gas library api will batch all requests it can.
You should also batch requests from VBA API. It will
automatically handle batching limits.
It’s easy. Just enclose various operations with .batch()
with getScriptDb("someSilo")
.batch(True)
.someoperations(...)
.someotheroperations(...)
.batch(false)

better
when
batched
example - create an object
Data is stored in silos within one or more ScriptDb
code
getScriptDb("somesilo") _
.createObject(JSONParse("{'customerid':1}"))

response (.jObject.stringify)
{

"status":"good",
"results":[]
}

better
when
batched
example - do a query
Queries are by example, and can include limit/skip
code
getScriptDb("somesilo") _
.getObjectsByQuery(JSONParse("{'customerid':1}"), JSONParse("{'limit':10}"))

response (.jObject.stringify)
{"status":"good","count":1,"results":[ {
"siloId":"somesilo",
"customerid":1,
"objectId":"S320799307189"
}]
}
example - update objects
All matching objects are updated to the given value. New
fields are created, existing fields are replaced
code
getScriptDb("somesilo") _
.updateObjects(JSONParse("{'customerid':1}"), JSONParse("{'name':'john'}"))

response (.jObject.stringify)
{ "status":"good","results":[]}
better
when
batched
example - count matching objects
Count operations can have optional queries
code
getScriptDb("somesilo") _
.count(JSONParse("{'customerid':1}")))

response
1
example - get object by id
Each object is assigned a unique Id returned by queries
code
getScriptDb("someSilo")
.getObjectById ("S320802188977")

response (.jObject.stringify)
{"status":"good","count":1,"results":[ {
"siloId":"somesilo",
"customerid":1,
"name":"john"
}]
}
example - delete objects
All objects matching the query are deleted
code
getScriptDb("somesilo").deleteObjects(JSONParse("{'customerid':1}"))

response (.jObject.stringify)
{"status":"good","count":0,"results":[ ]}

better
when
batched
example - load a spreadsheet to
scriptDb
Example add-on for this is included in workbook
code
populateFromSheet "VBAParseData"

Reading sheet and creating scriptDB objects
With dset.populateData(wholeSheet(sheetName), , , , , , True).jObject(, True, True)
For Each job In .children
Debug.Assert scriptdbCom.createObject(job).isOk
Next job
.tearDown
End With

better
when
batched
limits and skipping
Queries are subject to limits, so you need to work multiple
passes for big queries using skip/limit
Do
With sdb.getObjectsByQuery(Nothing, jobskip).jObject.child("results")
If .children.count = 0 Or Not sdb.isOk Then Exit Do
jobskip.child("skip").value = jobskip.child("skip").value + .children.count
For Each job In .children
jobStore.add , job.toString("objectId")
Next job

End With
Loop

{"results":["S320923864193","S320923308803", …. ]}

this is
automatically
handled for update
and delete
dates and times
These are handled the same was as
parse.com
"date":{

"__type":"Date",
"iso":"2013-08-22T00:00:00.000Z"
}

with supplied conversion function used like this
Debug.Print "date converted", getAnIsoDate(jor.child("date"))
silos and parse classes

•
•
•
•

A Silo is like a parse Class. For 2D data it
can be considered like a table.
Multiple classes can be held in the same
scriptDB.
scriptDB siloing is handled automatically
A seperate cScriptDbCom instance should
be instatiated for each class being worked
multiple scriptDB
•
•
•

The scriptDB dispatcher handled which actual scriptDB
to write to.
Multiple DBs can be used by referencing multiple
libraries in the scriptDB dispatcher.
Library names will be signalled to the dispatcher if they
are in the setup for this entry
scriptdbCom.init("anything", "some entry name", , "your app id", "your restapikey", , _
"some library",, "your web app Url")
restricting operations
You may want to allow a different kind of access to certain
users.
provide a different URL or use the app keys to signal
some restricted access , and include something like this
in the doGet() and doPost() functions

•
•

var whatsAllowed = ['query','count','getbyid'];

setting that configuration up under a different entry
scriptdbCom.init("anything", "some restricted entry", , "your app id", "your restapikey", , _
, "your restricted web app Url")
performance versus parse.com

•
•

Performance of parse.com as a rest API
handler seems to be much better than
scriptDB for most operations.
A full analysis will be published on Excel
Liberation and associated blog at some
future date
accessing from other apps

•
•
•

The scriptDB GAS handler API can be
accessed using any rest query mechanism.
The VBA API just manages the conversation
with the scriptDB GAS handler
Examples of other languages will be on
Excel Liberation at a later date.
public facing scriptdb
•
•
•

Normally access is controlled by oAuth2 - especially if
you are allowing write access.
oAuth2 is very much invisible in this API, as described
in this writeup, but you still need to get google
credentials
You can dispense with oAuth2 altogether for public
facing scriptdb by signalling false in the entry setup
scriptdbCom.init("anything", "readonly", , "your app id", "your restapikey", , "some library", False, _
"https://script.google.com/macros/s/AKfycbx7_gPpc38Map4QqHOQrzx_kvIX00nfYGO9OLq8_cMD486Va6M/exec")
further detail
All this code is downloadable or copyable from
Google Apps Script Libraries.
For more information see Excel Liberation

More Related Content

PDF
Using script db as a deaddrop to pass data between GAS, JS and Excel
PDF
Do something in 5 with gas 8-copy between databases
PDF
Do something in 5 with gas 9-copy between databases with oauth2
PPTX
Goa tutorial
PPTX
Google apps script database abstraction exposed version
PDF
JavaScript client API for Google Apps Script API primer
PPTX
Dbabstraction
PPTX
Google cloud datastore driver for Google Apps Script DB abstraction
Using script db as a deaddrop to pass data between GAS, JS and Excel
Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 9-copy between databases with oauth2
Goa tutorial
Google apps script database abstraction exposed version
JavaScript client API for Google Apps Script API primer
Dbabstraction
Google cloud datastore driver for Google Apps Script DB abstraction

What's hot (20)

PDF
Do something in 5 with apps scripts number 6 - fusion crossfilter
PDF
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
PDF
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
PDF
Do something in 5 with gas 3-simple invoicing app
PDF
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
PDF
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
PPTX
Logs management
PDF
Do something in 5 minutes with gas 1-use spreadsheet as database
PDF
Matt Jarvis - Unravelling Logs: Log Processing with Logstash and Riemann
PDF
Do something in 5 with gas 2-graduate to a database
PDF
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
PPTX
Using Cerberus and PySpark to validate semi-structured datasets
PPTX
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
PPTX
ASP.NET WEB API
PDF
Fetch data from form
PDF
Benchx: An XQuery benchmarking web application
PPTX
MongoDB - Sharded Cluster Tutorial
PDF
A real-world Relay application in production - Stefano Masini - Codemotion Am...
PDF
Db connection to qtp
PPTX
MongoDB Chunks - Distribution, Splitting, and Merging
Do something in 5 with apps scripts number 6 - fusion crossfilter
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something in 5 with gas 3-simple invoicing app
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Logs management
Do something in 5 minutes with gas 1-use spreadsheet as database
Matt Jarvis - Unravelling Logs: Log Processing with Logstash and Riemann
Do something in 5 with gas 2-graduate to a database
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
Using Cerberus and PySpark to validate semi-structured datasets
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
ASP.NET WEB API
Fetch data from form
Benchx: An XQuery benchmarking web application
MongoDB - Sharded Cluster Tutorial
A real-world Relay application in production - Stefano Masini - Codemotion Am...
Db connection to qtp
MongoDB Chunks - Distribution, Splitting, and Merging
Ad

Viewers also liked (8)

PPTX
Javascript like objects and JSON processing in VBA
PDF
Production Scheduling in a Job Shop Environment with consideration of Transpo...
PPT
job shop 111
PPTX
operations scheduling
PPT
Scheduling
PDF
Job shop scheduling
PPTX
Take Better Care of Library Data and Spreadsheets with Google Visualization A...
PDF
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Javascript like objects and JSON processing in VBA
Production Scheduling in a Job Shop Environment with consideration of Transpo...
job shop 111
operations scheduling
Scheduling
Job shop scheduling
Take Better Care of Library Data and Spreadsheets with Google Visualization A...
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
Teaching material agriculture food technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
Encapsulation_ Review paper, used for researhc scholars
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Teaching material agriculture food technology
Programs and apps: productivity, graphics, security and other tools
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

VBA API for scriptDB primer

  • 1. VBA API for ScriptDB Google Apps ScriptDB from Excel
  • 2. what is this API for? • • • • Allow maintenance and query Google Apps Script ScriptDB directly from VBA Share data in real time between Google Docs and Office a free noSQL database for Excel Migration or coexistence path for GAS and VBA
  • 4. authentication with oAuth2 One off credential storage user/google scope Registry ● Get oAuth2 credentials from Google Cloud Console ● Run the below to encrypt them on your PC, one time only. getGoogled("drive", , "xxxxx.apps.googleusercontent.com", "xxxxx").tearDown ● Credentials are shared between all VBA APIs needing oAuth2 on Excel Liberation ● Thereafter, oauth2 dance is automatically handled in all API requests
  • 5. optional access control User and Access type credentials your entry/ your scope Registry ● You can also optionally add a couple more keys, which are passed with every request in its header ● Equivalent to the RESTAPIkey and ApplicationID in parse.com ● Your Gas Webapp handler can inspect these to signal the GAS API the type of access allowed ● Only needs to be stored one time scriptdbCom.init("anything",”some entry id” ,”some scope id”, "your app id", _ "your restapikey", , , True, _ "Gas web app url endpoint").tearDown
  • 6. comparison with parse.com API VBA and GAS Main Apps are virtually the same code irrespective of the database cParseCom VBA API cParseCom GAS API cScriptDBCom VBA API parse.com restAPI handler GAS scriptDB webApp and API library parse.com cloud based noSQL database GAS scriptDB cloud based noSQL database
  • 7. optimization and batching • • • The gas library api will batch all requests it can. You should also batch requests from VBA API. It will automatically handle batching limits. It’s easy. Just enclose various operations with .batch() with getScriptDb("someSilo") .batch(True) .someoperations(...) .someotheroperations(...) .batch(false) better when batched
  • 8. example - create an object Data is stored in silos within one or more ScriptDb code getScriptDb("somesilo") _ .createObject(JSONParse("{'customerid':1}")) response (.jObject.stringify) { "status":"good", "results":[] } better when batched
  • 9. example - do a query Queries are by example, and can include limit/skip code getScriptDb("somesilo") _ .getObjectsByQuery(JSONParse("{'customerid':1}"), JSONParse("{'limit':10}")) response (.jObject.stringify) {"status":"good","count":1,"results":[ { "siloId":"somesilo", "customerid":1, "objectId":"S320799307189" }] }
  • 10. example - update objects All matching objects are updated to the given value. New fields are created, existing fields are replaced code getScriptDb("somesilo") _ .updateObjects(JSONParse("{'customerid':1}"), JSONParse("{'name':'john'}")) response (.jObject.stringify) { "status":"good","results":[]} better when batched
  • 11. example - count matching objects Count operations can have optional queries code getScriptDb("somesilo") _ .count(JSONParse("{'customerid':1}"))) response 1
  • 12. example - get object by id Each object is assigned a unique Id returned by queries code getScriptDb("someSilo") .getObjectById ("S320802188977") response (.jObject.stringify) {"status":"good","count":1,"results":[ { "siloId":"somesilo", "customerid":1, "name":"john" }] }
  • 13. example - delete objects All objects matching the query are deleted code getScriptDb("somesilo").deleteObjects(JSONParse("{'customerid':1}")) response (.jObject.stringify) {"status":"good","count":0,"results":[ ]} better when batched
  • 14. example - load a spreadsheet to scriptDb Example add-on for this is included in workbook code populateFromSheet "VBAParseData" Reading sheet and creating scriptDB objects With dset.populateData(wholeSheet(sheetName), , , , , , True).jObject(, True, True) For Each job In .children Debug.Assert scriptdbCom.createObject(job).isOk Next job .tearDown End With better when batched
  • 15. limits and skipping Queries are subject to limits, so you need to work multiple passes for big queries using skip/limit Do With sdb.getObjectsByQuery(Nothing, jobskip).jObject.child("results") If .children.count = 0 Or Not sdb.isOk Then Exit Do jobskip.child("skip").value = jobskip.child("skip").value + .children.count For Each job In .children jobStore.add , job.toString("objectId") Next job End With Loop {"results":["S320923864193","S320923308803", …. ]} this is automatically handled for update and delete
  • 16. dates and times These are handled the same was as parse.com "date":{ "__type":"Date", "iso":"2013-08-22T00:00:00.000Z" } with supplied conversion function used like this Debug.Print "date converted", getAnIsoDate(jor.child("date"))
  • 17. silos and parse classes • • • • A Silo is like a parse Class. For 2D data it can be considered like a table. Multiple classes can be held in the same scriptDB. scriptDB siloing is handled automatically A seperate cScriptDbCom instance should be instatiated for each class being worked
  • 18. multiple scriptDB • • • The scriptDB dispatcher handled which actual scriptDB to write to. Multiple DBs can be used by referencing multiple libraries in the scriptDB dispatcher. Library names will be signalled to the dispatcher if they are in the setup for this entry scriptdbCom.init("anything", "some entry name", , "your app id", "your restapikey", , _ "some library",, "your web app Url")
  • 19. restricting operations You may want to allow a different kind of access to certain users. provide a different URL or use the app keys to signal some restricted access , and include something like this in the doGet() and doPost() functions • • var whatsAllowed = ['query','count','getbyid']; setting that configuration up under a different entry scriptdbCom.init("anything", "some restricted entry", , "your app id", "your restapikey", , _ , "your restricted web app Url")
  • 20. performance versus parse.com • • Performance of parse.com as a rest API handler seems to be much better than scriptDB for most operations. A full analysis will be published on Excel Liberation and associated blog at some future date
  • 21. accessing from other apps • • • The scriptDB GAS handler API can be accessed using any rest query mechanism. The VBA API just manages the conversation with the scriptDB GAS handler Examples of other languages will be on Excel Liberation at a later date.
  • 22. public facing scriptdb • • • Normally access is controlled by oAuth2 - especially if you are allowing write access. oAuth2 is very much invisible in this API, as described in this writeup, but you still need to get google credentials You can dispense with oAuth2 altogether for public facing scriptdb by signalling false in the entry setup scriptdbCom.init("anything", "readonly", , "your app id", "your restapikey", , "some library", False, _ "https://script.google.com/macros/s/AKfycbx7_gPpc38Map4QqHOQrzx_kvIX00nfYGO9OLq8_cMD486Va6M/exec")
  • 23. further detail All this code is downloadable or copyable from Google Apps Script Libraries. For more information see Excel Liberation