Move oracle connection

This commit is contained in:
Ritchie Martori 2013-04-15 13:11:33 -07:00
parent e01e05f836
commit 430946345f
10 changed files with 17 additions and 50 deletions

View File

@ -27,8 +27,6 @@ function AsteroidModule(options) {
// throw an error if args are not supplied
assert(typeof options === 'object', 'AsteroidModule requires an options object');
this.options = validateOptions(options, this.constructor.optionsDefinition);
debug('created with options', options);
}
@ -51,39 +49,3 @@ AsteroidModule.defineOption = function (key, type, options) {
od[key] = options;
}
function validateOptions(options, def) {
if(!def) {
return options;
}
Object.keys(def).forEach(function (key) {
var val = options[key];
var keyDef = def[key] || {};
if(keyDef.required) {
assert(val, key + ' is required!');
}
// type
assert(typeof val == keyDef.type, key + ' must be a ' + keyDef.type);
// size / length
if(typeof val.length === 'number') {
if(keyDef.min) {
assert(val.length >= keyDef.min, key + ' length must be greater than or equal to ', keyDef.min);
}
if(keyDef.max) {
assert(val.length <= keyDef.min, key + ' length must be less than or equal to ', keyDef.max);
}
} else if(typeof val === 'number') {
if(keyDef.min) {
assert(val >= keyDef.min, key + ' must be greater than or equal to ', keyDef.min);
}
if(keyDef.max) {
assert(val <= keyDef.max, ' must be less than or equal to ', keyDef.max);
}
}
});
return options;
}

View File

@ -1,5 +0,0 @@
/**
* connection ~ public api
*/
module.exports = require('./lib/connection');

5
node_modules/oracle-connection/index.js generated vendored Normal file
View File

@ -0,0 +1,5 @@
/**
* connection ~ public api
*/
module.exports = require('./lib/oracle-connection');

View File

@ -8,8 +8,8 @@ module.exports = OracleConnection;
* Module dependencies.
*/
var Connection = require('asteroid-module')
, debug = require('debug')('connection')
var Connection = require('connection')
, debug = require('debug')('oracle-connection')
, util = require('util')
, inherits = util.inherits
, assert = require('assert');
@ -22,10 +22,13 @@ var Connection = require('asteroid-module')
*/
function OracleConnection(options) {
AsteroidModule.apply(this, arguments);
Connection.apply(this, arguments);
this.options = options;
debug('created with options', options);
// provide the oracle jugglingdb adapter
this.adapter = require('jugglingdb-oracle');
}
/**
@ -38,7 +41,9 @@ inherits(OracleConnection, Connection);
* Define options.
*/
OracleConnection.defineOption('hostname', 'string', {required: true});
OracleConnection.defineOption('port', 'number', {min: 10, max: 99999});
OracleConnection.defineOption('username', 'string');
OracleConnection.defineOption('password', 'string');
OracleConnection.options = {
'hostname': {type: 'string', required: true},
'port': {type: 'number', min: 10, max: 99999},
'username': {type: 'string'},
'password': {type: 'string'}
};