Permalink
Browse files

Fixed DB adapter connect/disconnect

  • Loading branch information...
1 parent 1aef6b9 commit 48fb464afa304d646f02a31827886030dc297e1b mde committed Aug 16, 2012
Showing with 26 additions and 7 deletions.
  1. +3 −0 lib/init/model.js
  2. +23 −7 templates/Jakefile
View
@@ -111,6 +111,9 @@ module.exports = new (function () {
config = _getAdapterConfig(geddy.config.db, adapterName);
adapterCtor = require(adapterPath).Adapter;
adapter = new adapterCtor(config);
+ if (typeof adapter.connect == 'function') {
+ adapter.connect();
+ }
model.loadedAdapters[adapterName] = adapter;
}
model.adapters[name] = adapter;
View
@@ -10,8 +10,8 @@ var fs = require('fs')
namespace('env', function () {
task('init', function () {
- geddy.model = require('model');
geddy.config = require('../lib/config').readConfig();
+ geddy.model = require('model');
require('../lib/init').init(complete);
@@ -22,22 +22,28 @@ namespace('env', function () {
task('cleanup', function () {
// Disconnect all the adapters
- adapters = geddy.model.loadedAdapters;
+ adapters = geddy.model.loadedAdapters
+ , adapter;
for (var p in adapters) {
- adapters[p].disconnect();
+ adapter = adapters[p];
+ if (typeof adapter.disconnect == 'function') {
+ adapter.disconnect();
+ }
}
});
}, {async: true});
namespace('db', function () {
- task('retrofit', ['env:init'], function () {
- var createTable
+
+ task('createTable', ['env:init'], function (name) {
+ var modelName = typeof name == 'string' ? [name] : name
+ , createTable
, adapters
, adapter
- , models = Object.keys(geddy.model.descriptionRegistry);
+ , modelNames = Object.keys(geddy.model.descriptionRegistry);
createTable = function () {
- if ((m = models.shift())) {
+ if ((m = modelNames.shift())) {
console.log('Creating table for ' + m);
adapter = geddy.model.adapters[m];
adapter.createTable(m, function (err, data) {
@@ -50,6 +56,16 @@ namespace('db', function () {
}
};
createTable();
+
+ }, {async: true});
+
+ task('retrofit', ['env:init'], function () {
+ var modelNames = Object.keys(geddy.model.descriptionRegistry)
+ , createTask = jake.Task['db:createTable'];
+ createTask.once('complete', function () {
+ complete();
+ });
+ createTask.invoke(modelNames);
}, {async: true});
});

0 comments on commit 48fb464

Please sign in to comment.