SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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 databaseBruce 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 databasesBruce 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
 
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 oauth2Bruce McPherson
 
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 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 crossfilterBruce McPherson
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineJason Terpko
 
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 2012Amazon Web Services
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNosh 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 APINils Breunese
 
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 ConnectorHenrik 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 DataMongoDB
 
Event-Driven Systems With MongoDB
Event-Driven Systems With MongoDBEvent-Driven Systems With MongoDB
Event-Driven Systems With MongoDBAndrii 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
 

Tendances (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
 

Similaire à 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 ExcelBruce 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 serverPavel Chertorogov
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-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 ApplicationAndrew 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 JAVASCRIPTAAFREEN SHAIKH
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
Javascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailJavascript Everywhere From Nose To Tail
Javascript Everywhere From Nose To TailCliffano 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) ExtensionVMware 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 RESTYos 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 problemdelagoya
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael Bright
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and PythonMike 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.0Frost
 
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 appsAlex Casquete
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english versionSabino Labarile
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHPAndrew Rota
 

Similaire à 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
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
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
 

Dernier

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Dernier (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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