-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
53 lines (50 loc) · 1.07 KB
/
database.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const config = require('./config.js');
Object.assign(exports, {
init(cb) {
mongoose.connect(
config.mongoose,
{ useNewUrlParser: true }
);
const db = mongoose.connection;
// Register models
mongoose.model(
'Job',
Schema({
title: String,
url: {
type: String,
match: [/^https?:/, 'URL is not HTTP(S) ({VALUE})']
},
query: {
mode: {
type: String,
enum: ['query', 'regex']
},
selector: String
},
interval: String,
enabled: {
type: Boolean,
default: true
},
values: [
{
time: Date,
value: String,
kind: {
type: String,
enum: ['number', 'text', 'error']
}
}
]
})
);
db.on('error', cb);
db.once('open', () => {
console.log('Successfully connected to database');
cb(null);
});
}
});