From 2ca8291eac6ee81cefbd1e6fe6393dbb45affa4c Mon Sep 17 00:00:00 2001 From: svelovla Date: Tue, 21 Oct 2014 15:28:10 +0200 Subject: [PATCH] #18 any-db-postgres, dbPool.js --- unleash-server/lib/api.js | 4 +++ unleash-server/lib/db.js | 1 + unleash-server/lib/dbPool.js | 22 ++++++++++++++ unleash-server/lib/eventMock.js | 53 +++++++++++++++++++++++++++++++++ unleash-server/package.json | 4 ++- 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 unleash-server/lib/dbPool.js create mode 100644 unleash-server/lib/eventMock.js diff --git a/unleash-server/lib/api.js b/unleash-server/lib/api.js index e71ea8828c..6d0a597b3c 100644 --- a/unleash-server/lib/api.js +++ b/unleash-server/lib/api.js @@ -33,5 +33,9 @@ module.exports = function (app) { }); }); + app.patch('/features/:id', function (req, res) { + res.status(500).end(); + }); + }; diff --git a/unleash-server/lib/db.js b/unleash-server/lib/db.js index 37a9fd166b..3b753a6fa0 100644 --- a/unleash-server/lib/db.js +++ b/unleash-server/lib/db.js @@ -1,5 +1,6 @@ var Promise = require('bluebird'); var featuresMock = require('./featuresMock'); +// var dbPool = require('./dbPool'); function getFeature(name) { var featureFound; diff --git a/unleash-server/lib/dbPool.js b/unleash-server/lib/dbPool.js new file mode 100644 index 0000000000..a2e2c2f4bc --- /dev/null +++ b/unleash-server/lib/dbPool.js @@ -0,0 +1,22 @@ +var anyDB = require('any-db'), + logger = require('./logger'), + nconf = require('nconf'), + fs = require('fs'), + ini = require('ini'); + + +function createDbPool() { + if (nconf.argv().get('databaseini') !== undefined) { + var databaseini = nconf.argv().get('databaseini'); + + logger.info('unleash started with databaseini: ' + databaseini); + + var config = ini.parse(fs.readFileSync(databaseini, 'utf-8')); + + return anyDB.createPool(config.DATABASE_URL, {min: 2, max: 20}); + } +} + +module.exports = { + pool: createDbPool() +}; \ No newline at end of file diff --git a/unleash-server/lib/eventMock.js b/unleash-server/lib/eventMock.js new file mode 100644 index 0000000000..5fac2c1945 --- /dev/null +++ b/unleash-server/lib/eventMock.js @@ -0,0 +1,53 @@ +module.exports = [ + { + "id": 1, + "created": "2014-08-01 12:22:00", + "type": "feature-create", + "user": "John, Doe", + "comment": "Optional comment", + "data": { + "name": "com.example.feature", + "status": "off", + "strategy": "default", + "description": "Feature description" + } + }, + { + "id": 2, + "created": "2014-09-02 15:23:11", + "type": "feature-update", + "user": "User name", + "comment": "Optional comment", + "data": { + "name": "com.example.feature", + "status": "on" + } + }, + { + "id": 3, + "created": "1970-01-01 00:00:00", + "type": "strategy-create", + "user": "User name", + "comment": "Optional comment", + "data": { + "name": "strategyA", + "parameters_template": { + "users": "example values", + "target_age": "number" + } + } + }, + { + "id": 4, + "created": "1970-01-01 00:00:00", + "type": "strategy-update", + "user": "localhost.localdomain", + "comment": "commit message goes here", + "data": { + "name": "strategyA", + "parameters_template": { + "users": "new default example values" + } + } + } +]; \ No newline at end of file diff --git a/unleash-server/package.json b/unleash-server/package.json index fb9644a376..90f73f1899 100644 --- a/unleash-server/package.json +++ b/unleash-server/package.json @@ -38,7 +38,9 @@ "ini": "1.3.0", "log4js": "0.6.21", "nconf": "0.6.9", - "pg": "^3.6.1" + "pg": "^3.6.1", + "any-db": "2.1.0", + "any-db-postgres": "2.1.3" }, "devDependencies": { "chai": "1.9.1",