From 05a6d686aaf2a20343cda046a1d4471bce56d0e2 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Fri, 21 Dec 2012 18:26:21 +0400 Subject: [PATCH] Strict adapter checking --- lib/railway.js | 29 ++++++++--------------------- package.json | 2 +- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/railway.js b/lib/railway.js index a02721d9..706e7c12 100644 --- a/lib/railway.js +++ b/lib/railway.js @@ -27,28 +27,13 @@ module.exports = function init(root) { var confFile = (root || app.root) + '/config/database'; var config = {}; - if (existsSync(confFile + '.js')) { - try { - config = require(confFile + '.js'); - } catch (e) { - console.log('Could not load config/database.js'); - throw e; - } - } else if (existsSync(confFile + '.json')) { - try { - config = JSON.parse(fs.readFileSync(confFile + '.json', 'utf-8'))[app.set('env')]; - } catch (e) { - console.log('Could not parse config/database.json'); - throw e; - } - } else if (existsSync(confFile + '.yml')) { - try { - config = railway.utils.readYaml(confFile + '.yml')[app.set('env')]; - } catch (e) { - console.log('Could not parse config/database.yml'); - throw e; - } + try { + config = require(confFile)[app.set('env')]; + } catch (e) { + console.log('Could not load config/database.{js|json|yml}'); + throw e; } + // when driver name started with point - look for driver in app root (relative path) if (config.driver && config.driver.match(/^\./)) { config.driver = path.join(app.root, config.driver); @@ -57,6 +42,8 @@ module.exports = function init(root) { var schema = new Schema(config && config.driver || 'memory', config); schema.log = log; + if (!schema.adapter) throw new Error('Adapter is not defined'); + if (schema.waitForConnect) { schema.on('connected', function() { loadSchema(schema, railway, app, models); diff --git a/package.json b/package.json index 399d37ee..08819933 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jugglingdb", "description": "ORM for every database: redis, mysql, neo4j, mongodb, couchdb, postgres, sqlite", - "version": "0.2.0-4", + "version": "0.2.0-6", "author": "Anatoliy Chakkaev ", "contributors": [ {