forked from zombitos/jay-mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (48 loc) · 1.14 KB
/
index.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
/* global module */
'use strict';
// -----------------------
// Deps
// -----------------------
var _ = require('underscore');
var when = require('when');
var schemas = {};
var Model = require('./lib/model');
var connManager = require('./lib/connectionManager');
var fs = require('fs');
// -----------------------
// Class Definition
// -----------------------
module.exports = {
// -----------------------
// Methods
// -----------------------
//SCOPE
//register
//pConnect
//model
/////
register: function register(key, jschema, methods) {
schemas[key] = new Model(key, jschema, methods);
},
//////
pConnect: function pConnect(connectUrl) {
return when.promise(function(resolve, reject) {
connManager.pConnect(connectUrl)
.then(function(db) {
return resolve(db);
}, function(err) {
return reject(err);
});
});
},
/////
loadModels: function loadModels(modelsPath) {
fs.readdirSync(modelsPath).forEach(function(file) {
if (~file.indexOf('.js')) require(modelsPath + file);
});
},
/////
model: function model(key) {
return _.clone(schemas[key]);
}
};