A few notes on scriptdb

If you take a look at Using scriptDB, you'll see that i use the cScriptDb functions from the mcpher library. This has some built in stuff including the following.
  • Siloing - using a silo limits records to those with a particular siloID.
  • User and timestamps - When the record was created, and by whom is automatically stamped.
  • Optional encryption - one way encryption can be applied to the userStamp. This way identities are never stored raw.
  • UserStamp filtering - this way all records are filtered by the current user - so for example you could not delete or examine the records of another user.
  • Abstraction - since the scriptdb to use is specified when initializing the silo, you can easily change the location of the underlying scriptdb for particular silos, without disturbing any code. See Using data from multiple scriptDB
When you are working with your badge environment, you are probably going to need to take a look inside, and possibly manipulate, some scriptDB. Here are a few examples using the silo manager. In this example, I've included these in my awards manager code. That means I'm using a local scriptDB (ScriptDb.getMyDb()). You can of course write this code in a different script, and attach your awards manager as a library and instead refer to that library's scriptDB.

Showing all awards in the database

Because I'm using a silo, this will only show award records. Anything else in your scriptdb will be ignored
function showAll() {
  var stuffSilo = mcpher.scriptDbSilo(mcpher.EBADGES.award,ScriptDb.getMyDb());
  var results = stuffSilo.query({});

  while (results.hasNext()) {
    var result = results.next();
    Logger.log(JSON.stringify(result));
  }
}

Deleting all the awards

Be careful if you have awarded badges. This will mean that the mozilla backpack will not be able to find the assertion. 
function deleteAll() {
  mcpher.scriptDbSilo(mcpher.EBADGES.award,ScriptDb.getMyDb()).remove();
}

Showing just my records

This will limit to only the records created by the currently logged on google user. Note that the optional encryption parameter must match how you wrote the record. In the case of awards records, the awardee email address is always one way encrypted.
function showAllMine() {
  var stuffSilo = mcpher.scriptDbSilo(mcpher.EBADGES.award,ScriptDb.getMyDb(),true,true,true);
  var results = stuffSilo.query({});

  while (results.hasNext()) {
    var result = results.next();
    Logger.log(JSON.stringify(result));
  }
}

Deleting just my records

This will limit to only the records created by the currently logged on google user. Note that the optional encryption parameter must match how you wrote the record. In the case of awards records, the awardee email address is always one way encrypted. Be careful if you have awarded badges. This will mean that the mozilla backpack will not be able to find the assertion. 

function deleteAllMine() {
  mcpher.scriptDbSilo(mcpher.EBADGES.award,ScriptDb.getMyDb(),true,true,true).remove();
}

Deleting a record by key

During the beta testing period, I also provide a way of deleting a record by key through URL. For example, something like this would delete a specific award record by key.

https://script.google.com/macros/s/AKfycbxZYXHPZrXkxJzeTiz7PJ-5th0g0w7s0DmxXR3o1v4AVSlmwBM/exec?key=324145545dc44c60dba232e7c07fcc0c0dcfeb094f1bafea125aa22f24aa992x&action=remove

cScriptDB silo code

To see how all that works, take a look at the code for cScriptDB


Trying out the badge infrastructure

You can learn how to incorporate Badges in your site or blog by reading How to set up your own badge environment

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













Comments