Playing around with the new Google Apps ScriptDB

I’m taking a break from d3.js and playing around with the new Apps Script DB. Those of you who read these posts or follow the rambling site may know that I have been building up a library of classes, modules and procedures that have equivalents in both Google Apps Script and Excel.

So what shall we do with ScriptDB? Well it gives us noSQL persistent storage associated with a Google Apps Script project. There are two main things I understood.

  • There are no separate tables. You break your data into ‘silos’ using some data type item
  • The database is associated with a project. I scratched my head for a bit when I found out that if you are using a library (which I am), then you can actually make the DB a persistent data store for your shared library – as opposed to the user project which calls it. 
The rest library is a perfect candidate for this – currently I set it up as a module, but let’s see if I can use ScriptDB to store the library, and make it available to all users (Excel or GAS). 
The first step is to deal with is this slightly annoying silo thing. I am going to store other things in this ScriptDB so I’ll create a silo Manager. You can find this class in the GAS mcpher shared library – I’ll get round to documenting it and writing it up in a later post, but in principle, you access the ScriptDB like this

 mcpher.scriptDbSilo(“some name or other”)

and all the nastiness to do with siloing the data is taken care of through whatever key you choose for your silo. The restLibrary  is a cJobject  that today is created in code. In the future it will be maintained in the scriptDB, but i need a one off to initially populating the scriptDB. Here’s how -( yes it’s a one-liner)

function restMake() {
  mcpher
   .scriptDbSilo(“restLibrary”)
   .save (mcpher.createRestLibrary().toNative());
}

Now that the library has been saved in the scriptDB (in a silo called restLibrary), I will need a way of accessing it with a future version of the rest Library module. I’ll use a function called getRestLibrary() that looks like this (another one liner)

function getRestLibrary() {
  return new cJobject()    .init(null,”root”)
    .fromNative(
       scriptDbSilo(“restLibrary”).query().next())
    .child(“restLibrary”);
}

 These libraries are available as per this post on managing shared GAS libraries (my shared libraries can be accessed using key MEQ3tE5y5_cTOAgUbUKSIAiz3TLx7pV4j ).

More on this to come…

Author: brucemcp

1 thought on “Playing around with the new Google Apps ScriptDB

Leave a Reply

Your email address will not be published. Required fields are marked *