Skip to content

Commit

Permalink
Start to implement the high-level wrapper on top of the drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Dec 31, 2009
1 parent ccbcd1e commit 606f58d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/persistence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var memory = require('./persistence/memory');

// Driver is the result of the new_connection method on a particular driver
function Backend(driver) {
this.driver = driver;
}
Backend.prototype = {

// Define takes an optional table name, and a structure
define: function () {

var args = Array.prototype.slice.call(arguments, 0),
name, columns, store, Resource;
if (args[0] instanceof String) {
name = args.shift();
}
columns = args.shift();
if (name) {
store = this.driver.get_store(name, columns);
} else {
store = memory.get_store(columns);
}
Resource = function (data) { };
Resource.prototype = {
save: function () { }
};
return Resource;
}

};

exports.Backend = Backend;
34 changes: 34 additions & 0 deletions lib/persistence/memory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var sys = require('sys');

function Store(conn, columns) {
this.conn = conn;
this.columns = columns;
this.data = [];
}
Store.prototype = {
get: function () {
throw "TODO: Implement Store.get()";
},
find: function () {
throw "TODO: Implement Store.find()";
},
each: function () {
throw "TODO: Implement Store.each()";
},
all: function () {
throw "TODO: Implement Store.all()";
},
save: function () {
throw "TODO: Implement Store.save()";
},
remove: function () {
throw "TODO: Implement Store.remove()";
},
nuke: function () {
throw "TODO: Implement Store.nuke()";
}
};

exports.get_store = function (columns) {
return new Store(this, columns);
};

0 comments on commit 606f58d

Please sign in to comment.