forked from 1602/jugglingdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
legacy-compound-schema-loader.js
36 lines (33 loc) · 1.11 KB
/
legacy-compound-schema-loader.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
module.exports = function(Schema, filename, settings, compound) {
var schema = [];
var definitions = require(filename);
Object.keys(definitions).forEach(function(k) {
var conf = settings[k];
if (!conf) {
console.log('No config found for ' + k + ' schema, using in-memory schema');
conf = {driver: 'memory'};
}
schema[k] = new Schema(conf.driver, conf);
schema[k].on('define', function(m, name, prop, sett) {
compound.models[name] = m;
if (conf.backyard) {
schema[k].backyard.define(name, prop, sett);
}
});
schema[k].name = k;
schema.push(schema[k]);
if (conf.backyard) {
schema[k].backyard = new Schema(conf.backyard.driver, conf.backyard);
}
if ('function' === typeof definitions[k]) {
define(schema[k], definitions[k]);
if (conf.backyard) {
define(schema[k].backyard, definitions[k]);
}
}
});
return schema;
function define(db, def) {
def(db, compound);
}
};