Permalink
Browse files

Start to re-implement memory in the new api.

  • Loading branch information...
1 parent 900f6f2 commit a518ccd69eb08b1a1c0dbafdea4d2e8baf0000ba @creationix committed Mar 18, 2010
Showing with 81 additions and 0 deletions.
  1. +30 −0 TODO
  2. +22 −0 lib/persistence/plain.js
  3. +29 −0 test.js
View
30 TODO
@@ -0,0 +1,30 @@
+Installation
+
+Configuring your DB connection
+
+Store Overview
+
+ Get(query, options, callback)
+ Insert(data, callback)
+ Update(data, query, options, callback)
+ Remove(query, options, callback)
+
+ query can be integer or options hash
+ if query is integer then its get / save / remove by ID
+ if query is an options hash assume A simple condition is pairs of key's and values. This builds a condition where all columns named by the key must equal the corresponding value.
+ if query is {}, assume all (like WHERE 1=1 in SQL land)
+
+ options is an options hash
+ limit - truncate the amount of rows returned
+
+ no-sql only
+ depth - integer - truncate the depth of nested objects
+ sort - callback function - sorts the results by custom method
+
+Saving data (Creates and Updates)
+
+Getting data (Reading and Searching)
+
+Removing data (Removing and Deleting)
+
+Using actual SQL with an RDBMS (not advised)
View
22 lib/persistence/plain.js
@@ -0,0 +1,22 @@
+var fs = require('fs');
+var defer = process.nextTick;
+
+exports.connect = function connect(filename, callback) {
+ defer(function () {
+ callback({
+ getStore: function getStore(name, callback) {
+ defer(function () {
+ callback({
+ get: function get(query, options, callback) {},
+ insert: function insert(data, callback) {},
+ update: function update(data, query, options, callback) {},
+ remove: function remove(query, options, callback) {}
+ });
+ })
+ },
+ close: function (callback) {
+ defer(callback);
+ }
+ });
+ });
+};
View
29 test.js
@@ -0,0 +1,29 @@
+var sys = require('sys');
+var Step = require('step');
+require('proto');
+
+var DbDriver = require('persistence/plain');
+
+Step(
+ function connect() {
+ sys.puts("connect");
+ DbDriver.connect('mydb.json', this);
+ },
+ function getStore(db) {
+ sys.puts("getStore");
+ this.db = db;
+ db.getStore("people", this);
+ },
+ function testStore(people) {
+ people.get();
+ people.update();
+ people.insert();
+ people.remove();
+ sys.puts("testStore");
+ sys.p(people);
+ this.db.close(this);
+ },
+ function done() {
+ sys.puts("done");
+ }
+);

0 comments on commit a518ccd

Please sign in to comment.