| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | (function(module) { | 
					
						
							|  |  |  | 	'use strict'; | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 	var mongoClient = require('mongodb').MongoClient, | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 		winston = require('winston'), | 
					
						
							|  |  |  | 		nconf = require('nconf'), | 
					
						
							| 
									
										
										
										
											2013-12-02 22:48:32 -05:00
										 |  |  | 		express = require('express'), | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 		mongoStore = require('connect-mongo')(express), | 
					
						
							|  |  |  | 		mongoHost = nconf.get('mongo:host'), | 
					
						
							|  |  |  | 		db; | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 	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'); | 
					
						
							| 
									
										
										
										
											2013-12-02 22:48:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 			if(err) { | 
					
						
							|  |  |  | 				winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message); | 
					
						
							|  |  |  | 				process.exit(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 			// TODO: fill out settings.db
 | 
					
						
							|  |  |  | 			module.sessionStore = new mongoStore({ | 
					
						
							|  |  |  | 				db: db | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 			db.createCollection('objects', function(err, collection) { | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 			db.createCollection('sets', function(err, collection) { | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 			callback(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		// look up how its done in mongo
 | 
					
						
							|  |  |  | 		/*if (nconf.get('mongo:password')) { | 
					
						
							|  |  |  | 			redisClient.auth(nconf.get('mongo:password')); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		*/ | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-02 22:48:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// Exported functions
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	module.getFileName = function(callback) { | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.info = function(callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// key
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.exists = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.delete = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.get = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.set = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 	//hashes
 | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	module.setObject = function(key, data, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 		data['_key'] = key; | 
					
						
							|  |  |  | 		db.collection('objects').insert(data, {w:1}, function(err, result) { | 
					
						
							|  |  |  | 			callback(err, result); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 	module.setObjectField = function(key, field, value, callback) { | 
					
						
							|  |  |  | 		db.collection('objects').update(); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getObject = function(key, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 		console.log('calling findOne'); | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 		db.collection('objects').findOne({_key:key}, function(err, item) { | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 			console.log(item); | 
					
						
							|  |  |  | 			callback(err, item); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getObjectField = function(key, field, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 		module.getObjectFields(key, [field], function(err, data) { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			callback(null, data[field]); | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getObjectFields = function(key, fields, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:08 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getObjectValues = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.isObjectField = function(key, field, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.deleteObjectField = function(key, field, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.incrObjectField = function(key, field, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.decrObjectField = function(key, field, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 	module.incrObjectFieldBy = function(key, field, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 	// sets
 | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 13:36:44 -05:00
										 |  |  | 	module.setAdd = function(key, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.setRemove = function(key, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.isSetMember = function(key, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.isMemberOfSets = function(sets, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getSetMembers = function(key, callback) { | 
					
						
							|  |  |  | 		console.log('getting set members'); | 
					
						
							|  |  |  | 		db.collection('sets').findOne({_key:key}, function(err, data) { | 
					
						
							|  |  |  | 			console.log('derp', err, data); | 
					
						
							|  |  |  | 			callback(err, data); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.setCount = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.setRemoveRandom = function(key, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// sorted sets
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.sortedSetAdd = function(key, score, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.sortedSetRemove = function(key, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getSortedSetRange = function(key, start, stop, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getSortedSetRevRange = function(key, start, stop, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getSortedSetRevRangeByScore = function(args, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.sortedSetCount = function(key, min, max, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// lists
 | 
					
						
							|  |  |  | 	module.listPrepend = function(key, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.listAppend = function(key, value, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.getListRange = function(key, start, stop, callback) { | 
					
						
							|  |  |  | 		throw new Error('not-implemented'); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-02 16:19:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }(exports)); | 
					
						
							|  |  |  | 
 |