SlideShare a Scribd company logo
javaScript/jQuery
API for ScriptDB
Google Apps ScriptDB from a webapp
what is this API for?
● Allow maintenance and query Google Apps
Script ScriptDB directly from a client webapp
● Share data in real time between Google
Docs, webapps and Excel (using VBA API
for Excel)
● a free noSQL database for javascript
webapps and Excel
COMPONENTS
the same handlers are used by
the VBA API

Your
Your
Your
code
code
client
code

cookie

simple
noSql

Your
ScriptDB
dispatcher

rest
scriptdb
API

scripdb api credentials

Your
Your
code
Multiple
code
ScriptDB

Your GAS
webapp
Handler (s)
GAS
Library
API
access control
User and
Access
type
credentials
your entry/
your scope

cookie

●
●

Can be used to control access operations by
endpoint
Only needs to be stored one time
new cScriptDbCom().setScriptCredentials( {
endPoint : gasHandlerEndPoints.scriptdbrequesthandler,
restAPIKey : 'xliberationApp',
scopeEntry : 'rest',
credentialsEntry: 'dbTest',
clientKey:'xliberation',
library: 'dbTest',
needDebug: false,
needOauth: false } );
comparison with parse.com and
VBA scriptDB API
VBA and GAS Main Apps are virtually the
same code irrespective of the whether parse
or scriptdb is used

VBA and javascript clients have similar code
and share the same GAS handlers and
databases

cParseCom VBA
API

cScriptDBCom
VBA API

cParseCom
GAS API

cScriptDBCom
javascript API

parse.com restAPI handler

GAS scriptDB webApp and API library

parse.com cloud based noSQL
database

GAS scriptDB cloud based noSQL database
note on examples
All the examples that follow put their results in a
page element using this function
/* display contents of some object at given element
* @param {object} control some object
* @param {string} id the id of the element
* @return {null}
*/
function renderScriptDb(control,id) {
$(id).text(JSON.stringify(control));
}
optimization and batching
● The gas library api will batch all requests it can.
● Batching is done automatically by the API
● Operations are asynchronous and orchestrated by
promises
getScriptDb("VBAParseCustomers","dbTest").getCount()
.done (function (data,cob) {
renderScriptDb(data.count,'#countcopycustomers');
})
.fail(function (data,cob) {
renderScriptDb(JSON.stringify(data),'#countcopycustomers');
});
example - create object (s)
Data is stored in silos within one or more ScriptDb
one object
dbTarget.createObject(data)
.done ( function(data) { .. do something good .. })
.fail ( function (error) { .. do something bad.. });

multiple objects
db.createObjects([some objects...])
.done( function (data) {...it worked..})
.fail( function (error) {...it failed..});
example - do a query
Queries are by example, and can include limit/skip
var dbCustomer = getScriptDb("VBAParseCustomers","dbTest");
dbCustomer.getObjectsByQuery({country:"United States"})
.done (function (data,cob) {
renderScriptDb(data.results,'#countryquery');
})
example - update objects
All matching objects are updated to the given value. New
fields are created, existing fields are replaced
getScriptDb("testClass","dbTest").updateObjects({town:’chicago’},null,{state:'IL’'})
.done(function(data){
renderScriptDb(data,'#bitupdate');
})
.fail(function(error){
renderScriptDb(error,'#bitupdate');
});
example - count matching objects
Count operations can have optional queries
getScriptDb("VBAParseCustomers",entry).getCount({country:"United States"})
.done (function (data,cob) {
renderScriptDb(data.count,'#countquery');
})
.fail(function (error,cob) {
renderScriptDb(fSON.stringify(error),'#countquery');
});
example - get object by id
Each object is assigned a unique Id returned by queries
getScriptDb("VBAParseCustomers",entry).getObjectById(objId)
.done (function (data,cob) {
renderScriptDb(data.results,'#id');
})
.fail(function (error,cob) {
renderScriptDb(JSON.stringify(error),'#id');
});
example - delete objects
All objects matching the query are deleted
dbTarget.deleteObjects({customerid:1})
.done (function (data,cob) {
renderScriptDb(data.results,'#delete');
})
.fail(function (error,cob) {
renderScriptDb(JSON.stringify(error),'#delete');
});
limits and skipping
Queries are subject to limits, so you can work multiple passes for big queries using skip/limit. A recursive convenience
method is provided to use, and show you how to do it (eg. db.getAllMatchingQueries({state:’IL’}) will take care of this
automatically as below - but watch out for memory usage)
self.getAllMatchingQueries = function (queryJob, queryParameters,list, defer) {
list = list || [];
defer = defer || $.Deferred();
var jobSkip = {skip:list.length};
self.getObjectsByQuery (queryJob, self.mergeParameters(queryParameters, jobSkip))
.done (function (data,defers) {
if (!data.results.length) {
defer.resolve(list);
}
else {
for (var i = 0 ; i < data.results.length; i++) {
list.push(data.results[i]);
}
self.getAllMatchingQueries(queryJob,queryParameters,list,defer);
}
})
.fail (function (error,defers){
defer.reject (error);
});
return defer.promise();
};

this is
automatically
handled for update
and delete
notes on finalFlush()
Because POST operations are batched, you need to call finalFlush() at some
point for each scriptdbcom instance. This clears any batch queues and resolves
any outstanding promises. It can be called as often and whenever you like, but
should be called at least once if there have been any POST type operations
(CREATE,UPDATE,DELETE), following the last one. Note that POST
operations are not resolved until they have been successfully flushed from the
Batch Queue.
finalFlush() also returns a promise for when all its work is complete.
dbTarget.finalFlush().then( function (data) { … do something , its all over… } );
dates and times
These are handled the same way as parse.com
"date":{
"__type":"Date",
"iso":"2013-08-22T00:00:00.000Z"
}
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
instantiated for each class being worked on
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
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
new cScriptDbCom().setScriptCredentials( {
endPoint : gasHandlerEndPoints.scriptdbrequesthandler,
restAPIKey : 'xliberationApp',
scopeEntry : 'rest',
credentialsEntry: 'dbTest',
clientKey:'xliberation',
library: 'dbTest',
needDebug: false,
needOauth: false } );
accessing from other apps
● The scriptDB GAS handler API can be
accessed using any rest query mechanism.
● The VBA API and javaScript 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
OAuth2 support is not yet released for the JavaScript
version (it is with the VBA one). This is because Google
Apps Script doesn’t yet support CORS (cross origin
resource sharing) for javaScript clients.
A temporary workaround for access control is described
here.
further detail
All this code is downloadable or copyable from
Google Apps Script Libraries.
For more information see Excel Liberation

More Related Content

PPTX
Google apps script database abstraction exposed version
PDF
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
PPTX
Dbabstraction
PDF
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
PDF
Do something in 5 with gas 3-simple invoicing app
PDF
Do something in 5 minutes with gas 1-use spreadsheet as database
PPTX
Goa tutorial
PPTX
Google cloud datastore driver for Google Apps Script DB abstraction
Google apps script database abstraction exposed version
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Dbabstraction
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 3-simple invoicing app
Do something in 5 minutes with gas 1-use spreadsheet as database
Goa tutorial
Google cloud datastore driver for Google Apps Script DB abstraction

What's hot (20)

PDF
Do something in 5 with gas 2-graduate to a database
PDF
Do something in 5 with gas 8-copy between databases
PDF
Do something in 5 with gas 7-email log
PDF
Do something in 5 with gas 9-copy between databases with oauth2
PDF
VBA API for scriptDB primer
PDF
Do something in 5 with apps scripts number 6 - fusion crossfilter
PPTX
MongoDB - Aggregation Pipeline
DOC
Database c# connetion
PPTX
MongoDB Aggregation
PDF
TXT
Bulk copy
PPT
Introduction to MongoDB
PDF
Improving Performance and Flexibility of Content Listings Using Criteria API
KEY
Ajax - a quick introduction
PDF
Analytics with MongoDB Aggregation Framework and Hadoop Connector
PDF
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
PPTX
Event-Driven Systems With MongoDB
PDF
Indexing and Query Optimizer (Mongo Austin)
PPTX
Apache Spark - Aram Mkrtchyan
PPTX
Data visualization by Kenneth Odoh
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 7-email log
Do something in 5 with gas 9-copy between databases with oauth2
VBA API for scriptDB primer
Do something in 5 with apps scripts number 6 - fusion crossfilter
MongoDB - Aggregation Pipeline
Database c# connetion
MongoDB Aggregation
Bulk copy
Introduction to MongoDB
Improving Performance and Flexibility of Content Listings Using Criteria API
Ajax - a quick introduction
Analytics with MongoDB Aggregation Framework and Hadoop Connector
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
Event-Driven Systems With MongoDB
Indexing and Query Optimizer (Mongo Austin)
Apache Spark - Aram Mkrtchyan
Data visualization by Kenneth Odoh
Ad

Similar to JavaScript client API for Google Apps Script API primer (20)

PPTX
Ui5 con@Banglore - UI5 App with Offline Storage using PouchDB
PDF
Using script db as a deaddrop to pass data between GAS, JS and Excel
ODP
Intravert Server side processing for Cassandra
ODP
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
PPT
Developing node-mdb: a Node.js - based clone of SimpleDB
PDF
API Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
PDF
Security Challenges in Node.js
PPTX
PostgreSQL, MongoDb, Express, React, Structured
PPTX
NodeJS
PDF
Intro to HTML5 Web Storage
PDF
Advanced JavaScript Development
PDF
Introduction to MongoDB
PPTX
MongoDB.local Sydney: Evolving your Data Access with MongoDB Stitch
PDF
Enterprise workflow with Apps Script
PDF
Evolving your Data Access with MongoDB Stitch
PPTX
Create Rest API in Nodejs
PDF
Getting started with node JS
PDF
Fast REST APIs Development with MongoDB
PDF
ECMAScript.Next ECMAScipt 6
PDF
Es.next
Ui5 con@Banglore - UI5 App with Offline Storage using PouchDB
Using script db as a deaddrop to pass data between GAS, JS and Excel
Intravert Server side processing for Cassandra
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
Developing node-mdb: a Node.js - based clone of SimpleDB
API Driven Application - AngulatJS, NodeJS and MongoDB | JCertif Tunisia 2015
Security Challenges in Node.js
PostgreSQL, MongoDb, Express, React, Structured
NodeJS
Intro to HTML5 Web Storage
Advanced JavaScript Development
Introduction to MongoDB
MongoDB.local Sydney: Evolving your Data Access with MongoDB Stitch
Enterprise workflow with Apps Script
Evolving your Data Access with MongoDB Stitch
Create Rest API in Nodejs
Getting started with node JS
Fast REST APIs Development with MongoDB
ECMAScript.Next ECMAScipt 6
Es.next
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
Group 1 Presentation -Planning and Decision Making .pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine Learning_overview_presentation.pptx
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
Getting Started with Data Integration: FME Form 101
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf

JavaScript client API for Google Apps Script API primer

  • 1. javaScript/jQuery API for ScriptDB Google Apps ScriptDB from a webapp
  • 2. what is this API for? ● Allow maintenance and query Google Apps Script ScriptDB directly from a client webapp ● Share data in real time between Google Docs, webapps and Excel (using VBA API for Excel) ● a free noSQL database for javascript webapps and Excel
  • 3. COMPONENTS the same handlers are used by the VBA API Your Your Your code code client code cookie simple noSql Your ScriptDB dispatcher rest scriptdb API scripdb api credentials Your Your code Multiple code ScriptDB Your GAS webapp Handler (s) GAS Library API
  • 4. access control User and Access type credentials your entry/ your scope cookie ● ● Can be used to control access operations by endpoint Only needs to be stored one time new cScriptDbCom().setScriptCredentials( { endPoint : gasHandlerEndPoints.scriptdbrequesthandler, restAPIKey : 'xliberationApp', scopeEntry : 'rest', credentialsEntry: 'dbTest', clientKey:'xliberation', library: 'dbTest', needDebug: false, needOauth: false } );
  • 5. comparison with parse.com and VBA scriptDB API VBA and GAS Main Apps are virtually the same code irrespective of the whether parse or scriptdb is used VBA and javascript clients have similar code and share the same GAS handlers and databases cParseCom VBA API cScriptDBCom VBA API cParseCom GAS API cScriptDBCom javascript API parse.com restAPI handler GAS scriptDB webApp and API library parse.com cloud based noSQL database GAS scriptDB cloud based noSQL database
  • 6. note on examples All the examples that follow put their results in a page element using this function /* display contents of some object at given element * @param {object} control some object * @param {string} id the id of the element * @return {null} */ function renderScriptDb(control,id) { $(id).text(JSON.stringify(control)); }
  • 7. optimization and batching ● The gas library api will batch all requests it can. ● Batching is done automatically by the API ● Operations are asynchronous and orchestrated by promises getScriptDb("VBAParseCustomers","dbTest").getCount() .done (function (data,cob) { renderScriptDb(data.count,'#countcopycustomers'); }) .fail(function (data,cob) { renderScriptDb(JSON.stringify(data),'#countcopycustomers'); });
  • 8. example - create object (s) Data is stored in silos within one or more ScriptDb one object dbTarget.createObject(data) .done ( function(data) { .. do something good .. }) .fail ( function (error) { .. do something bad.. }); multiple objects db.createObjects([some objects...]) .done( function (data) {...it worked..}) .fail( function (error) {...it failed..});
  • 9. example - do a query Queries are by example, and can include limit/skip var dbCustomer = getScriptDb("VBAParseCustomers","dbTest"); dbCustomer.getObjectsByQuery({country:"United States"}) .done (function (data,cob) { renderScriptDb(data.results,'#countryquery'); })
  • 10. example - update objects All matching objects are updated to the given value. New fields are created, existing fields are replaced getScriptDb("testClass","dbTest").updateObjects({town:’chicago’},null,{state:'IL’'}) .done(function(data){ renderScriptDb(data,'#bitupdate'); }) .fail(function(error){ renderScriptDb(error,'#bitupdate'); });
  • 11. example - count matching objects Count operations can have optional queries getScriptDb("VBAParseCustomers",entry).getCount({country:"United States"}) .done (function (data,cob) { renderScriptDb(data.count,'#countquery'); }) .fail(function (error,cob) { renderScriptDb(fSON.stringify(error),'#countquery'); });
  • 12. example - get object by id Each object is assigned a unique Id returned by queries getScriptDb("VBAParseCustomers",entry).getObjectById(objId) .done (function (data,cob) { renderScriptDb(data.results,'#id'); }) .fail(function (error,cob) { renderScriptDb(JSON.stringify(error),'#id'); });
  • 13. example - delete objects All objects matching the query are deleted dbTarget.deleteObjects({customerid:1}) .done (function (data,cob) { renderScriptDb(data.results,'#delete'); }) .fail(function (error,cob) { renderScriptDb(JSON.stringify(error),'#delete'); });
  • 14. limits and skipping Queries are subject to limits, so you can work multiple passes for big queries using skip/limit. A recursive convenience method is provided to use, and show you how to do it (eg. db.getAllMatchingQueries({state:’IL’}) will take care of this automatically as below - but watch out for memory usage) self.getAllMatchingQueries = function (queryJob, queryParameters,list, defer) { list = list || []; defer = defer || $.Deferred(); var jobSkip = {skip:list.length}; self.getObjectsByQuery (queryJob, self.mergeParameters(queryParameters, jobSkip)) .done (function (data,defers) { if (!data.results.length) { defer.resolve(list); } else { for (var i = 0 ; i < data.results.length; i++) { list.push(data.results[i]); } self.getAllMatchingQueries(queryJob,queryParameters,list,defer); } }) .fail (function (error,defers){ defer.reject (error); }); return defer.promise(); }; this is automatically handled for update and delete
  • 15. notes on finalFlush() Because POST operations are batched, you need to call finalFlush() at some point for each scriptdbcom instance. This clears any batch queues and resolves any outstanding promises. It can be called as often and whenever you like, but should be called at least once if there have been any POST type operations (CREATE,UPDATE,DELETE), following the last one. Note that POST operations are not resolved until they have been successfully flushed from the Batch Queue. finalFlush() also returns a promise for when all its work is complete. dbTarget.finalFlush().then( function (data) { … do something , its all over… } );
  • 16. dates and times These are handled the same way as parse.com "date":{ "__type":"Date", "iso":"2013-08-22T00:00:00.000Z" }
  • 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 instantiated for each class being worked on
  • 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
  • 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 new cScriptDbCom().setScriptCredentials( { endPoint : gasHandlerEndPoints.scriptdbrequesthandler, restAPIKey : 'xliberationApp', scopeEntry : 'rest', credentialsEntry: 'dbTest', clientKey:'xliberation', library: 'dbTest', needDebug: false, needOauth: false } );
  • 20. accessing from other apps ● The scriptDB GAS handler API can be accessed using any rest query mechanism. ● The VBA API and javaScript just manages the conversation with the scriptDB GAS handler ● Examples of other languages will be on Excel Liberation at a later date.
  • 21. public facing scriptdb OAuth2 support is not yet released for the JavaScript version (it is with the VBA one). This is because Google Apps Script doesn’t yet support CORS (cross origin resource sharing) for javaScript clients. A temporary workaround for access control is described here.
  • 22. further detail All this code is downloadable or copyable from Google Apps Script Libraries. For more information see Excel Liberation