forked from lambrojos/nodeintro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
38 lines (30 loc) · 748 Bytes
/
database.js
File metadata and controls
38 lines (30 loc) · 748 Bytes
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
var Db = require('tingodb')().Db;
var path = require('path');
/**
* TODO: We need to provide tingo db with a local path! to the db folder
*
* https://github.com/sergeyksv/tingodb
* https://nodejs.org/api/path.html#path_path_join_path1_path2
* https://nodejs.org/api/globals.html#globals_dirname
*/
//var dbPath = '?';
//
//
var db = null;
var dbPath = path.join(__dirname, 'db');
var db = new Db(dbPath, {});
var collection = db.collection('users');
exports.db = collection;
exports.plugin = (server, options, next) => {
collection.createIndex({id: 1}, {unique: true}, function(err, index){
if(err){
return err;
}
server.db = db;
next();
})
}
exports.plugin.attributes = {
name: 'db',
version: '0.1.0'
}