Using ScriptDB as a noSQL database for non-Google Apps Script clients

A long time back now, I showed how to publish and prettify source code and scriptdb contents using Google Apps Script. This allows you to embed code or data samples in blog posts and so on.

For example, below is the Google Apps Script code to do it, being shown live from the GAS IDE, using this link

http://xliberation.com/p/gaspubcontainer.html?source=script&module=Code&library=gasPublisher

ScriptDB as a non-Google Apps Script noSQL database

It can take a number of sources aside from Google Apps Script (such as gist, any url) and can return various formats, and select specific functions. One of the things it can do is to publish data inside a scriptDB. It occurred to me that with a minor tweak I could use it to query scriptDB (using the regular scriptDB query by example) and return JSON selected data  to Excel, or any app that would know what to do with JSON – meaning that we’d have a ready made noSQL database.

Test database

For testing I’ll use the scriptDB in this example showing how to use multiple databases. I’ve created a merged database and embedded it using the link below

http://xliberation.com/p/gaspubcontainer.html?source=scriptdb&module=accounts&library=useMultipleDB

Query by example

It would be useful if we could selectively take results from that scriptDB. That would give us a noSQL database to be used as reference outside of Google Apps Script. Well – all I have to do is pass the JSON that describes the query I want to make, In this case I want all records for customer named john, so I can use scriptDB query by example language and pass it as a parameter

http://xliberation.com/p/gaspubcontainer.html?source=scriptdb&module=accounts&library=useMultipleDB&query={“data”:{“customer”:{“name”:”john”}}}

and here’s the result…

Prettification

xliberation.com/p/gaspubcontainer.html is just a prettification wrapper for the Google Apps Script webapp that actually does the work. Below is that wrapper code (it’s being used to display itself)

http://xliberation.com/p/gaspubcontainer.html?source=web&module=http://xliberation.com/p/gaspubcontainer.html

Altogether now

So if you want to get this data, unadorned, into a web app you can simply call the underlying Google Apps Script directly giving it a type of ‘jsonp’ – adding a callback if you need one.

https://script.google.com/a/macros/mcpher.com/s/AKfycbzhzIDmgY9BNeBu87puxMVUlMkJ4UkD_Yvjdt5MhOxR1R6RG88/exec?type=jsonp&callback=yourfunction&source=scriptdb&module=accounts&library=useMultipleDB&query={“data”:{“customer”:{“name”:”john”}}}

Here’s a live query below from a simple web app

and here’s the source code

For more stuff like this see Excel Liberation

(function() {
var po = document.createElement(‘script’); po.type = ‘text/javascript’; po.async = true;
po.src = ‘https://apis.google.com/js/plusone.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(po, s);
})();

About brucemcp 224 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.

Be the first to comment

Leave a Reply

Your email address will not be published.


*