mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
added init method to database, progress made
This commit is contained in:
6
app.js
6
app.js
@@ -60,7 +60,7 @@
|
||||
nconf.file({
|
||||
file: __dirname + '/config.json'
|
||||
});
|
||||
meta = require('./src/meta.js');
|
||||
meta = require('./src/meta');
|
||||
|
||||
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path') + '/');
|
||||
nconf.set('upload_url', nconf.get('url') + 'uploads/');
|
||||
@@ -73,6 +73,7 @@
|
||||
winston.info('Base Configuration OK.');
|
||||
}
|
||||
|
||||
require('./src/database').init(function(err) {
|
||||
meta.configs.init(function () {
|
||||
|
||||
//
|
||||
@@ -96,7 +97,7 @@
|
||||
upgrade.check(function(schema_ok) {
|
||||
if (schema_ok || nconf.get('check-schema') === false) {
|
||||
websockets.init(SocketIO);
|
||||
console.log('calling plugins init');
|
||||
|
||||
plugins.init();
|
||||
global.templates = {};
|
||||
global.translator = translator;
|
||||
@@ -129,6 +130,7 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else if (nconf.get('setup') || nconf.get('install') || !fs.existsSync(__dirname + '/config.json')) {
|
||||
// New install, ask setup questions
|
||||
if (nconf.get('setup')) {
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
(function(module) {
|
||||
'use strict';
|
||||
var Db = require('mongodb').Db,
|
||||
mongoClient = require('mongodb').MongoClient,
|
||||
Server = require('mongodb').Server,
|
||||
var mongoClient = require('mongodb').MongoClient,
|
||||
winston = require('winston'),
|
||||
nconf = require('nconf'),
|
||||
express = require('express'),
|
||||
@@ -12,13 +10,11 @@
|
||||
mongoHost = nconf.get('mongo:host'),
|
||||
db;
|
||||
|
||||
|
||||
var db = new Db(nconf.get('mongo:database'), new Server(mongoHost, nconf.get('mongo:port')), {w:1});
|
||||
//console.log(db.collection);
|
||||
|
||||
db.open(function(err, _db) {
|
||||
//mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
|
||||
module.init = function(callback) {
|
||||
mongoClient.connect('mongodb://'+ mongoHost + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
|
||||
db = _db;
|
||||
console.log('WE ARE CONNECTED');
|
||||
|
||||
if(err) {
|
||||
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
|
||||
process.exit();
|
||||
@@ -29,28 +25,21 @@
|
||||
db: db
|
||||
});
|
||||
|
||||
db.collection('objects').findOne({_key:'config'}, {timeout:true}, function(err, item) {
|
||||
console.log('fail');
|
||||
console.log(item);
|
||||
callback(err, item);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
db.createCollection('objects', function(err, collection) {
|
||||
console.log('collection created', err, collection);
|
||||
});
|
||||
|
||||
db.createCollection('sets', function(err, collection) {
|
||||
|
||||
});
|
||||
|
||||
|
||||
callback(err);
|
||||
});
|
||||
// look up how its done in mongo
|
||||
/*if (nconf.get('mongo:password')) {
|
||||
redisClient.auth(nconf.get('mongo:password'));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
@@ -97,18 +86,46 @@
|
||||
|
||||
module.getObject = function(key, callback) {
|
||||
console.log('calling findOne');
|
||||
db.collection('objects').findOne({_key:key}, {timeout:true},function(err, item) {
|
||||
db.collection('objects').findOne({_key:key}, function(err, item) {
|
||||
console.log(item);
|
||||
callback(err, item);
|
||||
});
|
||||
}
|
||||
|
||||
module.getObjectField = function(key, field, callback) {
|
||||
throw new Error('not-implemented');
|
||||
module.getObjectFields(key, [field], function(err, data) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback(null, data[field]);
|
||||
})
|
||||
}
|
||||
|
||||
module.getObjectFields = function(key, fields, callback) {
|
||||
throw new Error('not-implemented');
|
||||
|
||||
var _fields = {};
|
||||
for(var i=0; i<fields.length; ++i) {
|
||||
_fields[fields[i]] = 1;
|
||||
}
|
||||
|
||||
db.collection('objects').findOne({_key:key}, {fields:_fields}, function(err, item) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var data = {};
|
||||
if(item === null) {
|
||||
for(var i=0; i<fields.length; ++i) {
|
||||
data[fields[i]] = null;
|
||||
}
|
||||
console.log('getObjectFields', data);
|
||||
return callback(null, data);
|
||||
}
|
||||
|
||||
console.log('getObjectFields', item);
|
||||
callback(err, item);
|
||||
});
|
||||
}
|
||||
|
||||
module.getObjectValues = function(key, callback) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
redis_socket_or_host = nconf.get('redis:host'),
|
||||
utils = require('./../../public/src/utils.js');
|
||||
|
||||
|
||||
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {
|
||||
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
|
||||
redisClient = redis.createClient(nconf.get('redis:host'));
|
||||
@@ -20,14 +21,13 @@
|
||||
redisClient = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
|
||||
}
|
||||
|
||||
module.client = redisClient;
|
||||
|
||||
module.sessionStore = new connectRedis({
|
||||
client: redisClient,
|
||||
ttl: 60 * 60 * 24 * 30
|
||||
});
|
||||
|
||||
module.client = redisClient;
|
||||
module.type = 'redis';
|
||||
|
||||
if (nconf.get('redis:password')) {
|
||||
redisClient.auth(nconf.get('redis:password'));
|
||||
}
|
||||
@@ -43,6 +43,11 @@
|
||||
});
|
||||
}
|
||||
|
||||
module.init = function(callback) {
|
||||
callback(null);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* A possibly more efficient way of doing multiple sismember calls
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,6 @@ var fs = require('fs'),
|
||||
Plugins.readyEvent = new eventEmitter;
|
||||
|
||||
Plugins.init = function() {
|
||||
console.log('plugins init called');
|
||||
if (Plugins.initialized) {
|
||||
return;
|
||||
}
|
||||
@@ -39,7 +38,7 @@ var fs = require('fs'),
|
||||
winston.info('[plugins] Plugins OK');
|
||||
}
|
||||
Plugins.initialized = true;
|
||||
plugins.readyEvent.emit('ready');
|
||||
Plugins.readyEvent.emit('ready');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var db = require('./database'),
|
||||
var //db = require('./database'),
|
||||
|
||||
// TODO: temp until upgrade is figured out with dbal,
|
||||
// db.client is redisClient for now
|
||||
RDB = db.client,
|
||||
RDB = require('./database/redis').client,
|
||||
|
||||
async = require('async'),
|
||||
winston = require('winston'),
|
||||
|
||||
Reference in New Issue
Block a user