aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.js')
-rw-r--r--src/database.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/database.js b/src/database.js
new file mode 100644
index 000000000..6fbd5dbc8
--- /dev/null
+++ b/src/database.js
@@ -0,0 +1,49 @@
1;(function () {
2 'use strict'
3
4 var config = require('config')
5 var mongoose = require('mongoose')
6
7 var logger = require('./logger')
8
9 var dbname = 'petube' + config.get('database.suffix')
10 var host = config.get('database.host')
11 var port = config.get('database.port')
12
13 // ----------- Videos -----------
14 var videosSchema = mongoose.Schema({
15 name: String,
16 namePath: String,
17 description: String,
18 magnetUri: String,
19 podUrl: String
20 })
21
22 var VideosDB = mongoose.model('videos', videosSchema)
23
24 // ----------- Pods -----------
25 var podsSchema = mongoose.Schema({
26 url: String,
27 publicKey: String
28 })
29
30 var PodsDB = mongoose.model('pods', podsSchema)
31
32 // ----------- Connection -----------
33
34 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
35 mongoose.connection.on('error', function () {
36 logger.error('Mongodb connection error.')
37 process.exit(0)
38 })
39
40 mongoose.connection.on('open', function () {
41 logger.info('Connected to mongodb.')
42 })
43
44 // ----------- Export -----------
45 module.exports = {
46 VideosDB: VideosDB,
47 PodsDB: PodsDB
48 }
49})()