Permalink
Browse files

Accept non-url format in mongoose adapter

  • Loading branch information...
1602 committed Nov 5, 2011
1 parent 9f9aa7c commit 683833b2202356746e4bfc625b122ee4aeb403d3
Showing with 25 additions and 1 deletion.
  1. +21 −0 lib/adapters/mongoose.js
  2. +4 −1 test/common_test.js
View
@@ -4,6 +4,27 @@
var mongoose = require('mongoose');
exports.initialize = function initializeSchema(schema, callback) {
+ if (!schema.settings.url) {
+ var url = schema.settings.host || 'localhost';
+ if (schema.settings.port) url += ':' + schema.settings.port;
+ var auth = '';
+ if (schema.settings.username) {
+ auth = schema.settings.username;
+ if (schema.settings.password) {
+ auth += ':' + schema.settings.password;
+ }
+ }
+ if (auth) {
+ url = auth + '@' + url;
+ }
+ if (schema.settings.database) {
+ url += '/' + schema.settings.database;
+ } else {
+ url += '/';
+ }
+ url = 'mongodb://' + url;
+ schema.settings.url = url;
+ }
schema.client = mongoose.connect(schema.settings.url);
schema.adapter = new MongooseAdapter(schema.client);
callback();
View
@@ -16,7 +16,10 @@ var schemas = {
username: 'root'
},
neo4j: { url: 'http://localhost:7474/' },
- mongoose: { url: 'mongodb://localhost/test' },
+ // mongoose: { url: 'mongodb://localhost/test' },
+ mongoose: {
+ database: 'test'
+ },
redis: {},
memory: {}
};

0 comments on commit 683833b

Please sign in to comment.