aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/database.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-06-09 17:41:40 +0200
committerChocobozzz <florian.bigard@gmail.com>2015-10-29 23:14:54 +0100
commit8c308c2bf7f658945d80be9d5880361238635f5b (patch)
tree2130ae60af58e59dab3df07a5d5cdd5174f91ae8 /src/database.js
parent8cb4b4e00ee57eb98dfe1455b6d2de36fc561797 (diff)
downloadPeerTube-8c308c2bf7f658945d80be9d5880361238635f5b.tar.gz
PeerTube-8c308c2bf7f658945d80be9d5880361238635f5b.tar.zst
PeerTube-8c308c2bf7f658945d80be9d5880361238635f5b.zip
Spawn
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})()