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

What's hot

Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a database
Bruce McPherson
 
Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesDo something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databases
Bruce 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 log
Bruce McPherson
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
Bruce McPherson
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
Bruce McPherson
 
Do something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilterDo something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilter
Bruce McPherson
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
Jason Terpko
 
Database c# connetion
Database c# connetionDatabase c# connetion
Database c# connetion
Christofer Toledo
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
Amit Ghosh
 
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
Amazon Web Services
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Nosh Petigara
 
Improving Performance and Flexibility of Content Listings Using Criteria API
Improving Performance and Flexibility of Content Listings Using Criteria APIImproving Performance and Flexibility of Content Listings Using Criteria API
Improving Performance and Flexibility of Content Listings Using Criteria API
Nils Breunese
 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introduction
Stefan Pettersson
 
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop ConnectorAnalytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Henrik Ingo
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB
 
Event-Driven Systems With MongoDB
Event-Driven Systems With MongoDBEvent-Driven Systems With MongoDB
Event-Driven Systems With MongoDB
Andrii Litvinov
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
MongoDB
 
Apache Spark - Aram Mkrtchyan
Apache Spark - Aram MkrtchyanApache Spark - Aram Mkrtchyan
Apache Spark - Aram Mkrtchyan
Hovhannes Kuloghlyan
 

What's hot (20)

Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
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 8-copy between databasesDo something in 5 with gas 8-copy between databases
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 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email log
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
Do something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilterDo something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilter
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
Database c# connetion
Database c# connetionDatabase c# connetion
Database c# connetion
 
MongoDB Aggregation
MongoDB Aggregation MongoDB Aggregation
MongoDB Aggregation
 
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
 
KMI System
KMI SystemKMI System
KMI System
 
Bulk copy
Bulk copyBulk copy
Bulk copy
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Improving Performance and Flexibility of Content Listings Using Criteria API
Improving Performance and Flexibility of Content Listings Using Criteria APIImproving Performance and Flexibility of Content Listings Using Criteria API
Improving Performance and Flexibility of Content Listings Using Criteria API
 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introduction
 
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop ConnectorAnalytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop Connector
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
 
Event-Driven Systems With MongoDB
Event-Driven Systems With MongoDBEvent-Driven Systems With MongoDB
Event-Driven Systems With MongoDB
 
Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)Indexing and Query Optimizer (Mongo Austin)
Indexing and Query Optimizer (Mongo Austin)
 
Apache Spark - Aram Mkrtchyan
Apache Spark - Aram MkrtchyanApache Spark - Aram Mkrtchyan
Apache Spark - Aram Mkrtchyan
 

Similar to JavaScript client API for Google Apps Script API primer

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
Bruce McPherson
 
GraphQL the holy contract between client and server
GraphQL the holy contract between client and serverGraphQL the holy contract between client and server
GraphQL the holy contract between client and server
Pavel Chertorogov
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
Tse-Ching Ho
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
Javascript
JavascriptJavascript
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
Cliffano Subagio
 
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) ExtensionSimplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
VMware Tanzu
 
Logisland "Event Mining at scale"
Logisland "Event Mining at scale"Logisland "Event Mining at scale"
Logisland "Event Mining at scale"
Thomas Bailet
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
Yos Riady
 
Soa development using javascript
Soa development using javascriptSoa development using javascript
Soa development using javascriptDsixE Inc
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
delagoya
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
Mike Bright
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
Michael Bright
 
Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0
Frost
 
Working with disconnected data in Windows Store apps
Working with disconnected data in Windows Store appsWorking with disconnected data in Windows Store apps
Working with disconnected data in Windows Store apps
Alex Casquete
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
Sabino Labarile
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
Andrew Rota
 

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

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
 
Grails 101
Grails 101Grails 101
Grails 101
 
GraphQL the holy contract between client and server
GraphQL the holy contract between client and serverGraphQL the holy contract between client and server
GraphQL the holy contract between client and server
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
Javascript
JavascriptJavascript
Javascript
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To Tail
 
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) ExtensionSimplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
 
Logisland "Event Mining at scale"
Logisland "Event Mining at scale"Logisland "Event Mining at scale"
Logisland "Event Mining at scale"
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
Soa development using javascript
Soa development using javascriptSoa development using javascript
Soa development using javascript
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0Building an api using golang and postgre sql v1.0
Building an api using golang and postgre sql v1.0
 
Working with disconnected data in Windows Store apps
Working with disconnected data in Windows Store appsWorking with disconnected data in Windows Store apps
Working with disconnected data in Windows Store apps
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 

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