Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

further progress on db internals

  • Loading branch information...
commit 6bb5610247438c569aaba95729239fa42b1e920a 1 parent 2e8755f
Chris Dew authored
31 lib/database.js
View
@@ -1,5 +1,30 @@
-exports.helloWorld = helloWorld;
+// This class represents a Database
-function helloWorld() {
- return "hello world";
+var util = require('util');
+var events = require('events');
+var table = require('./table');
+
+exports.hello = hello;
+exports.Database = Database;
+
+function hello() {
+ return "hello database";
+}
+
+function Database() {
+ this.tablesByName = {};
+}
+
+util.inherits(Database, events.EventEmitter);
+
+Database.prototype.createTable = function(tableSpec) {
+ this.tablesByName[tableSpec.name] = new table.Table(tableSpec);
+ //console.log(this);
+ this.emit('createTable', tableSpec);
+ return this;
+}
+
+
+Database.prototype.executeJson = function(json) {
+
}
15 lib/row.js
View
@@ -0,0 +1,15 @@
+var util = require('util');
+var events = require('events');
+
+exports.hello = hello;
+exports.Row = Row;
+
+function hello() {
+ return "hello row";
+}
+
+function Row() {
+ this._version = 1;
+}
+
+util.inherits(Row, events.EventEmitter);
23 lib/table.js
View
@@ -0,0 +1,23 @@
+// This class represents a Database
+
+var util = require('util');
+var events = require('events');
+
+exports.hello = hello;
+exports.Table = Table;
+
+function hello() {
+ return "hello table";
+}
+
+
+function Table(tableSpec) {
+ for (var p in tableSpec) {
+ this[p] = tableSpec[p];
+ }
+ this.rowsByPk = {};
+ this.pkName = null;
+ this.nextPk = 1;
+}
+
+util.inherits(Table, events.EventEmitter);
3  package.json
View
@@ -16,7 +16,8 @@
"express": "~3.0.3",
"telnet": "0.0.1",
"pegjs": "0.7.0",
- "jscoverage": "~0.2.5"
+ "jscoverage": "~0.2.5",
+ "socket.io": "~0.9.11"
},
"devDependencies": {
"mocha": "~1.7.0"
27 test/database-test.js
View
@@ -2,8 +2,31 @@ var assert = require("assert")
var database = require('../lib/database.js');
describe('Database', function() {
- it('should say "hello world"', function() {
- assert.equal("hello world", database.helloWorld());
+ it('should say "hello database"', function() {
+ assert.equal("hello database", database.hello());
+ });
+ it('should create an instance"', function() {
+ assert.deepEqual({tablesByName:{}}, new database.Database());
+ });
+ it('should be an instance of event emitter', function() {
+ assert.deepEqual("EventEmitter",
+ new database.Database().constructor.super_.name);
+ });
+ it('should create a table called mytable', function() {
+ assert.deepEqual( { tablesByName: { mytable: { name: "mytable"
+ , fields: [ { field: "id", type: "integer", pk: true, ai: true }
+ , { field: "foo", type: "varchar"}
+ ]
+ , rowsByPk: {}
+ , pkName: null
+ , nextPk: 1
+ } } }
+ , new database.Database().createTable(
+ { name:"mytable"
+ , fields:[ { field: 'id', type: 'integer', pk:true, ai:true }
+ , { field: 'foo', type: 'varchar' }
+ ]
+ } ) );
});
});
9 test/index-test.js
View
@@ -0,0 +1,9 @@
+var assert = require("assert")
+
+var subsql = require('../index.js');
+describe('SubSQL', function() {
+ it('should say "hello world"', function() {
+ assert.equal("hello world", subsql.helloWorld());
+ });
+});
+
15 test/test.js → test/parser-test.js
View
@@ -1,19 +1,4 @@
var assert = require("assert")
-describe('Array', function(){
- describe('#indexOf()', function(){
- it('should return -1 when the value is not present', function(){
- assert.equal(-1, [1,2,3].indexOf(5));
- assert.equal(-1, [1,2,3].indexOf(0));
- })
- })
-})
-
-var subsql = require('../index.js');
-describe('SubSQL', function() {
- it('should say "hello world"', function() {
- assert.equal("hello world", subsql.helloWorld());
- });
-});
var peg = require('pegjs');
var fs = require('fs');
16 test/row-test.js
View
@@ -0,0 +1,16 @@
+var assert = require("assert")
+
+var row = require('../lib/row.js');
+describe('Row', function() {
+ it('should say "hello row"', function() {
+ assert.equal("hello row", row.hello());
+ });
+ it('should create an instance"', function() {
+ assert.deepEqual({"_version": 1}, new row.Row());
+ });
+ it('should be an instance of event emitter', function() {
+ assert.deepEqual("EventEmitter",
+ new row.Row().constructor.super_.name);
+ });
+});
+
16 test/table-test.js
View
@@ -0,0 +1,16 @@
+var assert = require("assert")
+
+var table = require('../lib/table.js');
+describe('Table', function() {
+ it('should say "hello table"', function() {
+ assert.equal("hello table", table.hello());
+ });
+ it('should create an instance"', function() {
+ assert.deepEqual({"rowsByPk":{},"pkName":null,"nextPk":1}, new table.Table());
+ });
+ it('should be an instance of event emitter', function() {
+ assert.deepEqual("EventEmitter",
+ new table.Table().constructor.super_.name);
+ });
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.