What is scriptDBNOTE: ScriptDB is now deprecated. Please take a look at Database abstraction with google apps script for alternatives.scriptDB is a javaScript object database for Google Apps Script project. Here are a few key facts
Here's a summary of few of its uses from this site The Rest to Excel library is a good candidate to use the scriptDB to store its library data for both Excel and GAS. However, since I will be using the scriptDB for many things, I wanted to first formalize how I was going to approach data siloing, since that could get tiresome in the future.
I'm using a couple of new classes - cScriptDbSilo and cScriptDbSiloItem to automate that. Here's a test example that uses 2 differentt scriptDb - a local one, and the one associated with the mcpher shared library. ScriptDB also makes a useful lockBox.
function testThings(){ // delete everything from library and also from local mcpher.scriptDbSilo().remove(); mcpher.scriptDbSilo().remove(undefined,ScriptDb.getMyDb()); // add some stuff mcpher.scriptDbSilo("some library stuff").save({stuff:"library stuff"}); mcpher.scriptDbSilo("some local stuff",ScriptDb.getMyDb()).save({stuff:"local stuff"}); mcpher.scriptDbSilo("some local stuff").save({stuff2:"more local stuff"}); // show it mcpher.DebugPrint(mcpher.scriptDbSilo("some library stuff").query().next()); var results = mcpher.scriptDbSilo("some local stuff").query(); while (results.hasNext() ) { mcpher.DebugPrint(results.next()); } // delete it mcpher.scriptDbSilo("some library stuff").remove(); mcpher.scriptDbSilo("some local stuff").remove(); } That gives this result
{"siloId":"some library stuff","stuff":"library stuff"}
{"siloId":"some local stuff","stuff":"local stuff"} {"siloId":"some local stuff","stuff2":"more local stuff"} Walkthrough
Silos
Using a Silo manager like this enforces some standardization on how you partition data in this 'tableless' database. You can have as many silos as you want, each identified by some unique key.
Changing the default scriptDbIf the default scriptDb you want to use is not the one associated with the mcpher library, then you can change it by an initial call like this
mcpher.createDbSilos(
ScriptDb.getMyDb() ); or later by changing the xDb property
mcpher. scriptDbSilo().xDb = ScriptDb.getMyDb(); Deleting data in SilosYou are only able to delete data that you created. Items are written with a time stamp and the user who wrote it. Deleting checks that the user ID matches before allowing deletion. I'll also be updating this shortly to restrict shared library to read only.
The cScriptDbSilo codeYou can use the mcpher library mentioned in Creating a Google Apps Script Library to access this and to see the code. A snapshot of the code is in this gist and reproduced below.
CodeThe code is in the mcpher library. See here for how to incorporate it into your project.
SummaryTake a look at how the From VBA to Google Apps Script for more like this. Why not join our forum,follow the blog or follow me on twitter to ensure you get updates when they are available.
|
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > From VBA to Google Apps Script >