Skip to content

Commit

Permalink
Adjust the api to use node-style callbacks with error parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Mar 18, 2010
1 parent a518ccd commit c011ea1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lib/persistence/plain.js
@@ -1,22 +1,21 @@
var fs = require('fs'); var fs = require('fs');
var defer = process.nextTick; var defer = process.nextTick;



exports.connect = function connect(filename, callback) { exports.connect = function connect(filename, callback) {
defer(function () { defer(function () {
callback({ callback(null, {
getStore: function getStore(name, callback) { getStore: function getStore(name, callback) {
defer(function () { defer(function () {
callback({ callback(null, {
get: function get(query, options, callback) {}, get: function get(query, options, callback) {},
insert: function insert(data, callback) {}, insert: function insert(data, callback) {},
update: function update(data, query, options, callback) {}, update: function update(data, query, options, callback) {},
remove: function remove(query, options, callback) {} remove: function remove(query, options, callback) {}
}); });
}) })
}, },
close: function (callback) { close: defer
defer(callback);
}
}); });
}); });
}; };
11 changes: 7 additions & 4 deletions test.js
Expand Up @@ -9,12 +9,14 @@ Step(
sys.puts("connect"); sys.puts("connect");
DbDriver.connect('mydb.json', this); DbDriver.connect('mydb.json', this);
}, },
function getStore(db) { function getStore(err, db) {
sys.puts("getStore"); if (err) { throw err; }
sys.puts("getStore", sys.inspect(db));
this.db = db; this.db = db;
db.getStore("people", this); db.getStore("people", this);
}, },
function testStore(people) { function testStore(err, people) {
if (err) { throw err; }
people.get(); people.get();
people.update(); people.update();
people.insert(); people.insert();
Expand All @@ -23,7 +25,8 @@ Step(
sys.p(people); sys.p(people);
this.db.close(this); this.db.close(this);
}, },
function done() { function done(err) {
if (err) { throw err; }
sys.puts("done"); sys.puts("done");
} }
); );

0 comments on commit c011ea1

Please sign in to comment.