Move oracle connection
This commit is contained in:
parent
e01e05f836
commit
430946345f
|
@ -27,8 +27,6 @@ function AsteroidModule(options) {
|
||||||
// throw an error if args are not supplied
|
// throw an error if args are not supplied
|
||||||
assert(typeof options === 'object', 'AsteroidModule requires an options object');
|
assert(typeof options === 'object', 'AsteroidModule requires an options object');
|
||||||
|
|
||||||
this.options = validateOptions(options, this.constructor.optionsDefinition);
|
|
||||||
|
|
||||||
debug('created with options', options);
|
debug('created with options', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,39 +49,3 @@ AsteroidModule.defineOption = function (key, type, options) {
|
||||||
od[key] = 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;
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
/**
|
|
||||||
* connection ~ public api
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = require('./lib/connection');
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* connection ~ public api
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = require('./lib/oracle-connection');
|
|
@ -8,8 +8,8 @@ module.exports = OracleConnection;
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Connection = require('asteroid-module')
|
var Connection = require('connection')
|
||||||
, debug = require('debug')('connection')
|
, debug = require('debug')('oracle-connection')
|
||||||
, util = require('util')
|
, util = require('util')
|
||||||
, inherits = util.inherits
|
, inherits = util.inherits
|
||||||
, assert = require('assert');
|
, assert = require('assert');
|
||||||
|
@ -22,10 +22,13 @@ var Connection = require('asteroid-module')
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function OracleConnection(options) {
|
function OracleConnection(options) {
|
||||||
AsteroidModule.apply(this, arguments);
|
Connection.apply(this, arguments);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
debug('created with 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.
|
* Define options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OracleConnection.defineOption('hostname', 'string', {required: true});
|
OracleConnection.options = {
|
||||||
OracleConnection.defineOption('port', 'number', {min: 10, max: 99999});
|
'hostname': {type: 'string', required: true},
|
||||||
OracleConnection.defineOption('username', 'string');
|
'port': {type: 'number', min: 10, max: 99999},
|
||||||
OracleConnection.defineOption('password', 'string');
|
'username': {type: 'string'},
|
||||||
|
'password': {type: 'string'}
|
||||||
|
};
|
Loading…
Reference in New Issue