-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdb.js
More file actions
40 lines (32 loc) · 862 Bytes
/
db.js
File metadata and controls
40 lines (32 loc) · 862 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
39
40
const mongoose = require('mongoose');
const Promise = require('bluebird');
const schema = new mongoose.Schema({ name: 'string' });
const Organization = mongoose.model('Org', schema);
function dbConnect() {
return new Promise((resolve, reject) => {
mongoose.connect('mongodb://mongo:27017/org');
mongoose.connection.on('error', (e) => {
reject(e);
});
mongoose.connection.once('open', (e) => {
resolve(e);
});
});
}
const Orgs = (function () {
const save = (data = {}) => Promise.coroutine(function* () {
const orgsave = new Organization(data);
yield orgsave.save();
})();
const findOne = organization => Organization.findOne({ name: organization }).exec();
const find = () => Organization.find().exec();
return {
save,
findOne,
find,
};
})();
module.exports = {
dbConnect,
Orgs,
};