Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ktkaushik/sails-mongoose
base: master
...
head fork: ktkaushik/sails-mongoose
compare: temp
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 112 additions and 22 deletions.
  1. +100 −22 lib/adapter.js
  2. +11 −0 lib/mongooseUtils.js
  3. +1 −0  package.json
View
122 lib/adapter.js
@@ -40,7 +40,17 @@ module.exports = (function() {
registerCollection: function(collection, cb) {
var self = this,
collectionName;
-
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
+ console.log('in registerCollection of sails-mongoose');
+ console.log(collection);
// If the configuration in this collection corresponds
// with a known database, reuse it the connection(s) to that db
collectionName = utils.capitalize(collection.identity);
@@ -50,11 +60,14 @@ module.exports = (function() {
// Otherwise initialize for the first time
if (!dbs[ collectionName ]) {
- dbs[ collectionName ] = mongoose.model( collectionName, new Schema({}) );
+ // dbs[ collectionName ] = mongoose.model( collectionName, new Schema({}) );
+ this.define(collectionName, collection.definition, cb);
}
// adding defaults to every mongoose model
- dbs[ collectionName ].config = this.defaults;
+ // dbs[ collectionName ].config = this.defaults;
+
+ // dbs[collectionName].schema = {};
return cb();
},
@@ -77,18 +90,48 @@ module.exports = (function() {
define: function(collectionName, definition, cb) {
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
- console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
console.log('******************** you are in define **************************************************************');
+
+ var index, tempSchema,
+ schemaObject = {} ;
+
+ // Clone the definition
+ var def = _.clone(definition);
+ console.log(def);
+ // console.log('************** def *********************************');
+ function processKey(key, cb) {
+ // Remove any autoIncement keys, Mongo won't support them without
+ // a hacky additional collection
+
+ for(i in def){
+
+ if(def[key].autoIncrement) {
+ delete def[key].autoIncrement;
+ }
+
+ schemaObject[ key ] = monUtils.convertToMongooseType( def[key]['type'] );
+
+ // Mongoose will create a _id element for each schema object
+ if (key === 'id') {
+ delete key;
+ }else if(typeof tempSchema !== 'undefined'){
+ // console.log(' ======================== tempSchema is defined ==================== ');
+ // console.log( utils.capitalize(collectionName) );
+ tempSchema.add( schemaObject );
+ }else {
+ // console.log(' ======================== tempSchema is undefined ==================== ');
+ // console.log( utils.capitalize(collectionName) );
+ tempSchema = new Schema( schemaObject );
+ }
+
+ modelName = utils.capitalize( collectionName );
+
+ dbs[modelName] = mongoose.model(modelName, tempSchema);
+
+ return cb();
+ }
+ }
+ /*
spawnConnection(function __DEFINE__(connection, cb) {
connection.createCollection(collectionName, function __DEFINE__(err, result) {
// console.log('******************** you are in createCollection **************************************************************');
@@ -182,7 +225,8 @@ module.exports = (function() {
});
});
});
- }, dbs[collectionName].config, cb);
+ }, dbs[collectionName].config, cb); */
+
},
drop: function(collectionName, cb) {
@@ -226,12 +270,12 @@ module.exports = (function() {
create: function(collectionName, data, cb) {
console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
console.log('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ create $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
- console.log( data );
+ console.log( typeof data );
var modelName, modelInstance, tempObject;
modelName = utils.capitalize( collectionName );
modelInstance = mongoose.models[ modelName ];
- tempObject = new modelInstance;
+ tempObject = new modelInstance( data );
for(i in data){
console.log('given %%%%%%%%%% = ' + data[i]);
@@ -327,8 +371,6 @@ module.exports = (function() {
modelName = utils.capitalize( collectionName );
modelInstance = mongoose.models[ modelName ];
- console.log(options);
-
if (options.where) {
if (options.where.id != 'create') {
options.query = monUtils.covertIdForMongoose( options.where );
@@ -340,9 +382,6 @@ module.exports = (function() {
options.query = options.where;
}
- console.log('&&&&&&&&&&&&&&&&&& options after pre processing &&&&&&&&&&&&&&&&&&&&&&&&&&');
- console.log(options);
-
modelInstance.find(options.query, function(err, records) {
if(err) throw err;
return cb(err, utils.rewriteIds(records));
@@ -404,6 +443,45 @@ module.exports = (function() {
},
+ populate: function(collectionName, options, cb) {
+ console.log('in populate of sails-mongoose #####################################################################################################################');
+ console.log(collectionName);
+ console.log(cb);
+
+ var modelName, modelIntance, tempObject, options;
+ /**
+ * Should DRY this soon
+ */
+ modelName = utils.capitalize( collectionName );
+ modelInstance = mongoose.models[ modelName ];
+ options = criteria.rewriteCriteria(options);
+
+
+ if (options.where) {
+ if (options.where.id != 'create') {
+ options.query = monUtils.covertIdForMongoose( options.where );
+ }else {
+ console.log(options.where);
+ options.query = options.where;
+ }
+ }else{
+ options.query = options.where;
+ }
+
+ // Author.findOne('5225ba09dc3299b310000001').populate('books').done(function(err, rec){console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'); console.log(rec); });
+ // console.log(modelInstance);
+ // return modelInstance.find( options.query ).populate(cb).exec();
+ modelInstance.find( options.query ).populate( cb ).exec(function(err, record) {
+ console.log('inside the exec of populate !!!');
+ if(err) throw err;
+ console.log(record);
+ console.log(record[cb]);
+ console.log('inside the exec of populate !!!');
+ return record;
+ });
+
+ },
+
update: function(collectionName, options, values, cb) {
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
View
11 lib/mongooseUtils.js
@@ -55,6 +55,17 @@ module.exports = {
case 'dt':
mongooseObject = Date;
break;
+
+ case 'associate':
+ console.log('this is an association');
+ if ( this.ref ){
+ // reference association
+ //author: [{ type: 'Schema.Types.ObjectId', ref: 'Author' } ]
+ mongooseObject = [{ type: Schema.Types.ObjectId, ref: this.ref }];
+ }else{
+ // embedded association
+ };
+ break;
}
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mongooseObject ********************************************************* ');
console.log(mongooseObject);
View
1  package.json
@@ -31,6 +31,7 @@
"async": "0.2.9",
"underscore": "1.4.4",
"underscore.string": "2.3.1",
+ "mongodb": "1.3.8",
"mongoose": "latest"
},
"devDependencies": {

No commit comments for this range

Something went wrong with that request. Please try again.