Skip to content
Browse files

rename table file to model

  • Loading branch information...
1 parent 6ca78c6 commit 384387a9ba78c3064f14c43bdb064fe664311531 @ssinghi ssinghi committed Feb 3, 2011
Showing with 43 additions and 34 deletions.
  1. +1 −4 index.js
  2. +6 −5 lib/belongs_to.js
  3. +3 −2 lib/field.js
  4. +7 −5 lib/model.js
  5. +4 −3 lib/query.js
  6. +2 −1 lib/record.js
  7. +7 −5 lib/to_many.js
  8. +1 −1 lib/utils.js
  9. +1 −1 test.js
  10. +3 −1 tests/collection.js
  11. +1 −1 tests/item.js
  12. +3 −2 tests/test-model.js
  13. +2 −2 tests/test-query.js
  14. +2 −1 tests/user.js
View
5 index.js
@@ -1,5 +1,2 @@
-var rdx = exports.rdx = new Object();
-rdx.ConnectionPool = require('./lib/connection').ConnectionPool;
-rdx.Model = require('./lib/table').Table;
-
+module.exports = require('./lib')
View
11 lib/belongs_to.js
@@ -1,9 +1,9 @@
-var Query = require('./query').Query;
-var Utils = require('./utils').Utils;
-var Model = require('./table').Model;
-var Field = require('./field').Field;
+var Query = require('./query');
+var Utils = require('./utils');
+var Model = require('./model');
+var Field = require('./field');
-var BelongsTo = exports.BelongsTo = function(chained_object, join_key, join_table) {
+var BelongsTo = function(chained_object, join_key, join_table) {
if(!(join_table instanceof Model)) new Error(join_table + " is not an instance of Model");
if(!(join_key instanceof Field)) new Error(join_key + " is not an instance of Field");
@@ -16,6 +16,7 @@ var BelongsTo = exports.BelongsTo = function(chained_object, join_key, join_tabl
return t;
};
+modules.exports = BelongsTo;
BelongsTo.prototype.query = function() {
var q = new Query();
View
5 lib/field.js
@@ -1,6 +1,6 @@
-var Utils = require('./utils').Utils;
+var Utils = require('./utils');
-Field = exports.Field = function(table, field_desc) {
+var Field = function(table, field_desc) {
if(field_desc) {
if(typeof(field_desc) === 'string') {
this.name = field_desc;
@@ -15,6 +15,7 @@ Field = exports.Field = function(table, field_desc) {
this._alias;
this.table = table;
}
+module.exports = Field;
Field.prototype.toSql = function() {
var fn = (this.table ? this.table.tableName + '.' : '') + (this.name ? this.name : '*');
View
12 lib/model.js
@@ -1,11 +1,11 @@
-var Query = require('./query').Query;
-var Record = require('./record').Record;
-var Field = require('./field').Field;
-var Utils = require('./utils').Utils;
+var Field = require('./field');
+var Query = require('./query');
+var Record = require('./record');
+var Utils = require('./utils');
var table_function = function() { return function(arg) { Record.call(this); if(arg) { Utils.extend(this, arg); }; };};
-var Model = exports.Model = Model = function(connection_pool, table_name) {
+var Model = function(connection_pool, table_name) {
Query.call(this);
var func = table_function();
@@ -28,6 +28,8 @@ var Model = exports.Model = Model = function(connection_pool, table_name) {
return func;
};
+module.exports = Model;
+
Model.prototype.__proto__ = Query.prototype;
//Model.prototype = new Query();
View
7 lib/query.js
@@ -1,8 +1,8 @@
-var Field = require('./field').Field;
-var Utils = require('./utils').Utils;
+var Field = require('./field');
+var Utils = require('./utils');
var Events = require('events');
-var Query = exports.Query = function (){
+var Query = function (){
this._select = [];
this._from = [];
this._where = [];
@@ -16,6 +16,7 @@ var Query = exports.Query = function (){
this._chain = null;
this._chained_object = null;
};
+module.exports = Query;
Query.prototype = Object.create(Events.EventEmitter.prototype);
View
3 lib/record.js
@@ -1,9 +1,10 @@
var Events = require('events');
-var Record = exports.Record = function() {
+var Record = function() {
this.newRecord = true;
this.destroyed = false;
};
+module.exports = Record;
Record.prototype = Object.create(Events.EventEmitter.prototype);
View
12 lib/to_many.js
@@ -1,9 +1,9 @@
-var Query = require('./query').Query;
-var Utils = require('./utils').Utils;
-var Model = require('./table').Model;
-var Field = require('./field').Field;
+var Utils = require('./utils');
+var Model = require('./model');
+var Field = require('./field');
+var Query = require('./query');
-var ToMany = exports.ToMany = function(chained_object, join_table, join_key ){
+var ToMany = function(chained_object, join_table, join_key ){
if(!(join_table instanceof Model)) new Error(join_table + " is not an instance of Model");
if(!(join_key instanceof Field)) new Error(join_key + " is not an instance of Field");
@@ -17,6 +17,8 @@ var ToMany = exports.ToMany = function(chained_object, join_table, join_key ){
return t;
};
+module.exports = ToMany;
+
ToMany.prototype.query = function() {
var q = new Query();
var connection = this.joinModel.connectionPool.getConnection();
View
2 lib/utils.js
@@ -1,4 +1,4 @@
-var Utils = exports.Utils = new Object();
+var Utils = module.exports = new Object();
function Clone() { }
View
2 test.js
@@ -20,6 +20,6 @@ catch(e) {
}
process.chdir(__dirname);
-reporter.run(['tests/test-table.js','tests/test-query.js', 'tests/test-field.js']);
+reporter.run(['tests/test-model.js','tests/test-query.js', 'tests/test-field.js']);
View
4 tests/collection.js
@@ -1,5 +1,7 @@
var cp = require('./setup').RDXTestConnectionPool();
-var Model = require('table').Model;
+var Model = require('model');
+
+
var Item = require('./item').Item;
var Collection = exports.Collection = new Model(cp, 'collections');
View
2 tests/item.js
@@ -1,4 +1,4 @@
var cp = require('./setup').RDXTestConnectionPool();
-var Model = require('table').Model;
+var Model = require('model');
var Item = exports.Item = new Model(cp, 'items');
View
5 tests/test-model.js
@@ -1,5 +1,6 @@
-var Model = require('table').Model;
-var Query = require('query').Query;
+var Model = require('model');
+var Query = require('query');
+
var User = require('./user').User;
var Collection = require('./collection').Collection;
View
4 tests/test-query.js
@@ -1,5 +1,5 @@
-var Query = require('query').Query;
-var Field = require('field').Field;
+var Query = require('query');
+var Field = require('field');
var Collection = require('./collection').Collection;
var User = require('./user').User;
View
3 tests/user.js
@@ -1,5 +1,6 @@
var cp = require('./setup').RDXTestConnectionPool();
-var Model = require('table').Model;
+var Model = require('model');
+
var Collection = require('./collection').Collection;
var User = exports.User = new Model(cp, 'users');

0 comments on commit 384387a

Please sign in to comment.
Something went wrong with that request. Please try again.