diff --git a/server/package.json b/server/package.json index 46de8c4..dd92674 100644 --- a/server/package.json +++ b/server/package.json @@ -23,6 +23,7 @@ "@types/koa": "^2.0.45", "@types/koa-bodyparser": "^4.2.0", "@types/koa-router": "^7.0.28", + "@types/nedb": "^1.8.0", "axios": "^0.18.0", "babel-core": "^6.26.3", "babel-loader": "^7.1.4", @@ -35,6 +36,7 @@ "koa": "^2.5.1", "koa-bodyparser": "^4.2.1", "koa-router": "^7.4.0", + "nedb": "^1.8.0", "node-loader": "^0.6.0", "nodemon": "^1.17.5", "ts-loader": "^4.4.1", diff --git a/server/src/config.ts b/server/src/config.ts index 6aefcb9..43efee1 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -10,6 +10,10 @@ export const ANALYTICS_PATH = path.join(__dirname, '../../analytics'); export const DATA_PATH = path.join(__dirname, '../../data'); +export const ANALYTIC_UNITS_DATABASE_PATH = path.join(DATA_PATH, 'analyticUnits.db'); +export const METRICS_DATABASE_PATH = path.join(DATA_PATH, 'metrics.db'); +export const SEGMENTS_DATABASE_PATH = path.join(DATA_PATH, 'segments.db'); + export const DATASETS_PATH = path.join(DATA_PATH, 'datasets'); export const ANALYTIC_UNITS_PATH = path.join(DATA_PATH, 'analytic_units'); export const MODELS_PATH = path.join(DATA_PATH, 'models'); diff --git a/server/src/services/data_service.ts b/server/src/services/data_service.ts index af23925..8897b68 100644 --- a/server/src/services/data_service.ts +++ b/server/src/services/data_service.ts @@ -1,7 +1,13 @@ import * as config from '../config' +import * as nedb from 'nedb'; import * as fs from 'fs'; +export const db = { + analyticUnits: new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true }), + metrics: new nedb({ filename: config.METRICS_DATABASE_PATH, autoload: true }), + segments: new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true }) +}; // see analytics/pattern_detection_model.py with folders available