NOTE: ScriptDB is now deprecated. Please take a look at Database abstraction with google apps script for alternatives.

There are a number of examples on this site of one library being used to provide data to another script. You may want to do this for a number of reasons.

  • The limit for a scriptDB is 50mb. A scriptDB is associated with a script, and one script can reference multiple libraries. It follows then that if you use multiple libraries, you can create multiple 50mb scriptDBs for a given application. Note though that there is a 50mb overall quota for a particular user, so if you did plan to go over 50mb in total, you could create additional google apps IDs, and create additional scripts in these as required.
  • You may want to partition your data such that different applications should have access to only certain items. Applications would associate with different libraries (and access their scriptDB) depending on how you wanted to organize that.
  • In Siloing, i showed how to  split up the scriptdb into sections so that multiple kinds of data can be kept in the same DB. This gives the added benefit of abstraction – the silo class itself worries about the physical db, not your calling module. That means that you can, if necessary move data around without making any changes in your calling application, whether for space or organizational reasons.

An example

Let’s say that we wanted to keep customer data in a separate DB from orders data, with various applications accessing one or both of these data items. To demonstrate this, I’m going to create 3 scripts.
  • customersDB
  • ordersDB
  • useMultipleDB
The first two are libraries, that are referenced by the third, like this. I’m using functions from the mcpher library, so we need that too.

Taking a look at the orders and customers libraries, they could not be simpler. Their only role is to provide a handle into their respective scriptDBs and the code for each is exactly the same aside from the arbitrary silo name I’ve assigned .

Now here’s an example application

And here’s the logged output

For help and more information join our forum, follow the blog or follow me on Twitter