add db init method, prepare for db testing

This commit is contained in:
oleg 2015-06-29 20:42:57 +03:00
parent f38275a0f9
commit cec79bdc75
6 changed files with 80 additions and 63 deletions

8
app.js
View File

@ -1,6 +1,7 @@
'use strict';
var http = require('http'),
var db = require('./db'),
http = require('http'),
nodeStatic = require('node-static'),
jade = require('jade'),
path = require('path'),
@ -72,6 +73,11 @@ Steppy(
console.log('Server config:', JSON.stringify(app.config, null, 4));
notifier.init(app.config.notify, this.slot());
db.init('path/to/db/ignored/for/memdown', {
db: require('memdown'),
valueEncoding: 'json'
}, this.slot());
},
function() {
// load all projects for the first time

20
db.js
View File

@ -2,11 +2,11 @@
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
nlevel = require('nlevel'),
ldb = nlevel.db('path/to/db/ignored/for/memdown', {
db: require('memdown'),
valueEncoding: 'json'
});
nlevel = require('nlevel');
exports.init = function(dbPath, params, callback) {
var ldb = nlevel.db(dbPath, params, callback);
exports.builds = new nlevel.DocsSection(ldb, 'builds', {
projections: [
@ -26,10 +26,6 @@ exports.builds = new nlevel.DocsSection(ldb, 'builds', {
]
});
function pickProjectName(build) {
return build.project.name;
}
exports.builds._beforePut = function(builds, callback) {
var self = this,
build;
@ -68,6 +64,12 @@ exports.builds._beforePut = function(builds, callback) {
callback
);
};
};
function pickProjectName(build) {
return build.project.name;
}
function generateIds(section, docs, callback) {
Steppy(

5
test/db/concurrent.js Normal file
View File

@ -0,0 +1,5 @@
'use strict';
describe('Db concurrency', function() {
});

3
test/db/index.js Normal file
View File

@ -0,0 +1,3 @@
'use strict';
require('./concurrent');

View File

@ -1,6 +1,7 @@
'use strict';
require('./commands');
require('./db');
require('./scm');
require('./executor');
require('./node');