// ----------------------------------------------------------------------------

var crypto = require('crypto');
var util = require('util');

var DynoAbstract = require('dyno-abstract');

// ----------------------------------------------------------------------------

var DynoMemory = function() {
    var self = this;

    // call the superclass
    DynoMemory.super_.call(this);

    // create our store
    self.store = {};

    return self;
};
util.inherits(DynoMemory, DynoAbstract);

// ----------------------------------------------------------------------------

// _putOperation(operationName, itemName, timestamp, operation, change, callback) -> (err)
//
// This replaces the entire item. It does not put individual attributes.
DynoMemory.prototype._putOperation = function(operationName, itemName, timestamp, change, callback) {
    var self = this;

    // create the data to store
    var data = {
        name      : itemName,
        operation : operationName,
        timestamp : timestamp,
        change    : change,
    };

    // see if this item already exists
    if ( self.store[itemName] ) {
        self.store[itemName].push(data);
    }
    else {
        // make a new one
        self.store[itemName] = [ data ];
    }

    console.log(util.inspect(self.store, false, null, true));

    // simulate IO
    process.nextTick(function() {
        callback(null);
    });
};

// _getChangesets(itemName, callback) -> (err, changesets)
//
// This retrieves all changesets for this item
DynoAbstract.prototype._getChangesets = function(itemName, callback) {
    var self = this;

    // To get all of the changesets, we just return the item (if it exists). We make a copy of it
    // so that it hasn't disappeared when we come back after nextTick()
    var item;
    if ( self.store[itemName] ) {
        // terrible way to clone
        item = JSON.parse(JSON.stringify(self.store[itemName]));
    }
    else {
        item = [];
    }

    // simulate IO
    process.nextTick(function() {
        callback(null, item);
    });
};

// ----------------------------------------------------------------------------

// the createDynoMemory() function
module.exports = exports = function createDynoMemory(filename) {
    return new DynoMemory(filename);
};

// ----------------------------------------------------------------------------

@@ -2131,16 +2131,887 @@
 ------%0A%0A
+// query(query) -%3E (err, items)%0A//%0A// query(%7B start : 'james', end : 'john' %7D, callback);%0A//%0A// This returns all the items between 'start' and 'end'.%0ADynoMemory.prototype.query = function(query, callback) %7B%0A    var self = this;%0A%0A    // get all the keys in this store%0A    var keys = Object.keys(self.store).sort();%0A%0A    // save the items which match the input query%0A    var items = %5B%5D;%0A    keys.forEach(function(key, i) %7B%0A        // ignore this key if it is outside the range we want%0A        if ( query.start && key %3C query.start ) return;%0A        if ( query.end   && key %3E query.end   ) return;%0A%0A        // ok, looks like we have an item%0A        var item = self.reduce(self.store%5Bkey%5D);%0A        items.push(item);%0A    %7D);%0A%0A    // return all the items we found%0A    callback(null, items);%0A%7D;%0A%0A// ----------------------------------------------------------------------------%0A%0A
 // the c

Add an implementation of Dyno.query()