Skip to content

Commit

Permalink
file cleanup, submodule cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nw committed May 11, 2010
1 parent 07671c6 commit 27cd72b
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 158 deletions.
5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/support/class"]
path = lib/support/class
url = http://github.com/visionmedia/class.js.git
[submodule "lib/support/mongodb"]
path = lib/support/mongodb
url = git@github.com:nw/node-mongodb-native.git
url = http://github.com/christkv/node-mongodb-native.git
2 changes: 1 addition & 1 deletion examples/models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Model.define('User', {
Mongoose.Model.define('User', {

collection : 'test_user',

Expand Down
31 changes: 0 additions & 31 deletions examples/new_model.js

This file was deleted.

92 changes: 0 additions & 92 deletions examples/run.js

This file was deleted.

12 changes: 0 additions & 12 deletions examples/sugar.js

This file was deleted.

14 changes: 11 additions & 3 deletions examples/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var sys = require('sys'),

var objs = [],
usernames = ['Nathan','Guillermo','Damian','Thianh','Rafael','Matt','Keeto'],
lastnames = ['Corrales','Lu','Rauch','Walker','Walker','Suarez'],
lastnames = ['Corrales','Lu','Rauch','Walker','White','Suarez'],
ages = [19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40];

Array.prototype.random = function(){
Expand All @@ -35,6 +35,14 @@ var sys = require('sys'),
});

hydrate = true;
User.find({}).limit(20).each(function(doc){
User.find({}).limit(20).gt({'bio.age' : 20}).lt({'bio.age' : 25}).each(function(doc){
sys.puts(doc.first_last+' legal drinking age?: '+ doc.legalDrinkingAge);
},hydrate);
// sys.puts(JSON.stringify(doc));
},hydrate);

Mongoose.close();

// setTimeout(function(){
// Mongoose.close();
// },500);
// Mongoose.close();
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ var fs = require('fs'),
files.forEach(function(file){
if(fs.statSync(file).isFile())
var sandbox = {},
code = fs.readFileSync(file);
// sandbox[this.options.sandboxName] = this;
// sandbox['Model'] = this.Model;
// sandbox['require'] = require;
var Mongoose = this;
var Model = Mongoose.Model;
eval(code);
// Script.runInThisContext(code /*,sandbox */);
code = fs.readFileSync(file) + "\n\n__func_proto__ = Function.prototype;";
sandbox[this.options.sandboxName] = this;
sandbox['Model'] = this.Model;
sandbox['require'] = require;
Script.runInNewContext(code ,sandbox );
for(i in Function.prototype) if(!sandbox.__func_proto__[i]) sandbox.__func_proto__[i] = Function.prototype[i];
}.bind(this));
},

Expand Down Expand Up @@ -115,7 +113,7 @@ var fs = require('fs'),

close : function(){
for(conn in this.connections)
if(this.connections[conn] instanceof Storage) this.connections[conn].close();
if(this.connections[conn] instanceof Storage) this.connections[conn].db.close();
},

parseURI : function(uri){
Expand Down
12 changes: 12 additions & 0 deletions lib/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ var object = require('../utils/object'),
else this.emit('error','Model ['+model.name+'] is already defined.');
},

close : function(){
for(i in this.models){
for(b in this.models[i].binds){
var model = this.models[i].binds[b];
model.halt();
model.clear();
model.collection = null;
model.loaded = false;
}
}
},

compile : function(name,store){

var Mongoose = this.mongoose,
Expand Down
14 changes: 10 additions & 4 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var mongo = require('./support/mongodb/lib/mongodb/'),
},

collection : function(){ return this._cmd('collection',Array.prototype.slice.call(arguments,0)); },
close : function(){ return this._cmd('close', Array.prototype.slice.call(arguments,0)); },
// close : function(){ return this._cmd('close', Array.prototype.slice.call(arguments,0)); },

_cmd : function(cmd,args){
var operation = {
Expand Down Expand Up @@ -121,9 +121,15 @@ var mongo = require('./support/mongodb/lib/mongodb/'),
},

close : function(){
for(col in this.collections)
this.collections[col].close();
this.db.close();
this.halt();
this.clear();
for(col in this.collections){
this.collections[col].close(function(){});
delete this.collections[col];
}
this.db.close(function(){});
delete this.db;
this.loaded = false;
}
};

Expand Down
1 change: 0 additions & 1 deletion lib/support/class
Submodule class deleted from 6fa0d5

0 comments on commit 27cd72b

Please sign in to comment.