Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Mongo adapter needs ref to base model, fixes for table create/drop

  • Loading branch information...
commit 8182d448a37cf6cf8593ea4705ec9fbc81b9f536 1 parent d196c2b
mde authored
View
28 lib/adapters/mongo/index.js
@@ -1,4 +1,5 @@
-var file = require('utilities').file
+var model = require('../../index')
+ , file = require('utilities').file
, driver = file.requireLocal('mongodb-wrapper')
, utils = require('utilities')
, operation = require('../../query/operation')
@@ -321,8 +322,11 @@ utils.mixin(Adapter.prototype, new (function () {
var self = this
, collections = Array.isArray(names) ? names.slice() : [names]
, create = function () {
- var c;
+ var c
+ , tableName;
if ((c = collections.shift())) {
+ tableName = utils.inflection.pluralize(c);
+ tableName = utils.string.snakeize(tableName);
self.client.createCollection(c, {}, create);
}
else {
@@ -332,6 +336,26 @@ utils.mixin(Adapter.prototype, new (function () {
create();
};
+ this.dropTable = function (names, callback) {
+ var self = this
+ , collections = Array.isArray(names) ? names.slice() : [names]
+ , drop = function () {
+ var c
+ , tableName
+ , collection;
+ if ((c = collections.shift())) {
+ tableName = utils.inflection.pluralize(c);
+ tableName = utils.string.snakeize(tableName);
+ collection = self.client.collection(tableName);
+ collection.drop(drop);
+ }
+ else {
+ callback();
+ }
+ };
+ drop();
+ };
+
})());
module.exports.Adapter = Adapter;
View
6 lib/adapters/sql/postgres.js
@@ -1,9 +1,9 @@
var file = require('utilities').file
, pg = file.requireLocal('pg')
- , generator = require('../../../lib/generators/sql')
+ , generator = require('../../generators/sql')
, utils = require('utilities')
- , model = require('../../../lib')
- , Query = require('../../../lib/query/query').Query
+ , model = require('../../index')
+ , Query = require('../../query/query').Query
, BaseAdapter = require('./base').Adapter
, Adapter
, _baseConfig;
View
14 test/adapters/mongo/index.js
@@ -24,21 +24,11 @@ tests = {
, 'Account': adapter
};
- Zooby.remove({}, function (err, data) {
- if (err) {
- throw err;
- }
- next();
- });
+ adapter.dropTable(['Zooby', 'User'], next);
}
, 'after': function (next) {
- Zooby.remove({}, function (err, data) {
- if (err) {
- throw err;
- }
- next();
- });
+ adapter.dropTable(['Zooby', 'User'], next);
}
, 'test create adapter': function () {
Please sign in to comment.
Something went wrong with that request. Please try again.