DovetailDB
Scripting Tutorial

Dovetaildb allows you to implement complex behavior in the server by writing scripts in a variety of languages. You should be able to use any JSR 233 compliant scripting language, inlcuding Javascript, Python, Ruby, Groovy, and Scheme. One list of JSR 233 implementations is available here.

Finding counts of items is not supported natively; it is a good candidate use case for a small script:

function count(bagname) {
  var iter = dovetaildb.query(bagname, java.util.HashMap(), java.util.HashMap())
  var count = 0;
  while (iter.hasNext()) {
    count+=1;
    iter.next();
  }
  return count;
}
To

No matter what scripting language you use, a variable named "dovetaildb" is exposed. This object has several methods defined on it:

You can implement a wrapper around this object that will intercept invocations, either from other scripts, or from the HTTP api. Such a wrapper corresponds roughly to triggers in a relational database, but are implemented more like "around advice" in AOP jargon.

// Force every object to store the time it was inserted into a member called "insertedTimestamp"
function put(bag, entry) {
    entry.insertedTimestamp = new Date().getTime();
    return dovetaildb.put(bag, entry);
}

// Nobody can query for people whose status is "hidden":
function query(bag, query, options) {
    if (bag == 'people') {
        query = ['&', [query, {"status":["!", "hidden"]}]]
    }
    return dovetaildb.query(bag, query, options);
}