-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"env": { | ||
"es6": false, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @class Database | ||
* @description | ||
* Represents configuration of a server driver. | ||
* | ||
* @param {Object} driver | ||
* Database driver object. | ||
* | ||
* @returns {Database} | ||
*/ | ||
function Database(driver) { | ||
|
||
if (!driver || typeof driver !== 'object') { | ||
throw new TypeError('Invalid driver specified.'); | ||
} | ||
|
||
if (!(this instanceof Database)) { | ||
return new Database(driver); | ||
} | ||
|
||
} | ||
|
||
module.exports = Database; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @class TypeAdapter | ||
* @class DataType | ||
* @description | ||
* Represents a single database type. | ||
* Represents a single data type. | ||
* | ||
* @param {Object} driverType | ||
* @param {Object} dt | ||
* Database Data Type. | ||
* | ||
* @returns {TypeAdapter} | ||
* @returns {DataType} | ||
*/ | ||
function TypeAdapter(driverType) { | ||
function DataType(dt) { | ||
|
||
if (!driverType || typeof driverType !== 'object') { | ||
throw new TypeError('Invalid driver specified.'); | ||
if (!dt || typeof dt !== 'object') { | ||
throw new TypeError('Invalid database type specified.'); | ||
} | ||
|
||
if (!(this instanceof TypeAdapter)) { | ||
return new TypeAdapter(driverType); | ||
if (!(this instanceof DataType)) { | ||
return new DataType(dt); | ||
} | ||
|
||
} | ||
|
||
module.exports = TypeAdapter; | ||
module.exports = DataType; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
'use strict'; | ||
|
||
var ConfigAdapter = require('./adapters/config'); | ||
var TypeAdapter = require('./adapters/type'); | ||
var nodeHighVer = +process.versions.node.split('.')[0]; | ||
|
||
module.exports = { | ||
ConfigAdapter: ConfigAdapter, | ||
TypeAdapter: TypeAdapter | ||
}; | ||
// istanbul ignore if | ||
if (nodeHighVer < 4) { | ||
throw new Error('Minimum Node.js version required by db-types is 4.x'); | ||
} | ||
|
||
var Database = require('./adapters/database'); | ||
var DataType = require('./adapters/type'); | ||
|
||
module.exports = {Database, DataType}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
var lib = require('../'); | ||
|
||
describe("Database", function () { | ||
|
||
it("must initialize correctly", function () { | ||
expect(lib.Database({}) instanceof lib.Database).toBe(true); | ||
expect(new lib.Database({}) instanceof lib.Database).toBe(true); | ||
}); | ||
|
||
it("must throw on invalid parameters", function () { | ||
var error = new TypeError('Invalid driver specified.'); | ||
expect(function () { | ||
lib.Database(undefined); | ||
}).toThrow(error); | ||
expect(function () { | ||
lib.Database(123); | ||
}).toThrow(error); | ||
expect(function () { | ||
lib.Database('hello'); | ||
}).toThrow(error); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
var lib = require('../'); | ||
|
||
describe("DataType", function () { | ||
|
||
it("must initialize correctly", function () { | ||
expect(lib.DataType({}) instanceof lib.DataType).toBe(true); | ||
expect(new lib.DataType({}) instanceof lib.DataType).toBe(true); | ||
}); | ||
|
||
it("must throw on invalid parameters", function () { | ||
var error = new TypeError('Invalid database type specified.'); | ||
expect(function () { | ||
lib.DataType(undefined); | ||
}).toThrow(error); | ||
expect(function () { | ||
lib.DataType(123); | ||
}).toThrow(error); | ||
expect(function () { | ||
lib.DataType('hello'); | ||
}).toThrow(error); | ||
}); | ||
|
||
}); |