-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.js
37 lines (33 loc) · 843 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var mongoose = require('mongoose'),
util = require('util'),
config = require('./config.json');
var connection_string = util.format(
'mongodb://%s:%s@%s:%d/%s',
config.mongo.user,
config.mongo.password,
config.mongo.hostname,
config.mongo.port,
config.mongo.database
);
if(connection_string.indexOf("localhost") !== -1 ) {
connection_string = connection_string.replace('undefined:undefined@', '');
};
mongoose.connect(connection_string);
var IRCLog = mongoose.model('IRCLog', {
ts: Date,
server: String,
channel: String,
message: String,
nick: String
});
var addLogItem = function(data) {
var item = new IRCLog(data);
item.save(function(err) {
if(err) {
console.log(err);
}
});
};
exports.log = {
add: addLogItem
};