Merge github.com:1602/jugglingdb
This commit is contained in:
commit
519d6cf7fb
|
@ -63,7 +63,7 @@ check following list of available adapters
|
|||
<!-- PostgreSQL -->
|
||||
<tr>
|
||||
<td><a href="http://www.postgresql.org/"><img src="http://www.postgresql.org/favicon.ico" style="vertical-align:middle"" alt="PostgreSQL" /></a> PostgreSQL</td>
|
||||
<td><a href="/1602/jugglingdb-nano">jugglingdb-postgres</a></td>
|
||||
<td><a href="/1602/jugglingdb-postgres">jugglingdb-postgres</a></td>
|
||||
<td><a href="/anatoliychakkaev">Anatoliy Chakkaev</a></td>
|
||||
<td><a href="https://travis-ci.org/1602/jugglingdb-postgres"><img src="https://travis-ci.org/1602/jugglingdb-postgres.png?branch=master" alt="Build Status" /></a></td>
|
||||
</tr>
|
||||
|
|
2
index.js
2
index.js
|
@ -7,7 +7,7 @@ exports.Validatable = require('./lib/validatable').Validatable;
|
|||
exports.BaseSQL = require('./lib/sql');
|
||||
|
||||
exports.init = function (rw) {
|
||||
if (typeof rw === 'string') {
|
||||
if (global.railway) {
|
||||
railway.orm = exports;
|
||||
} else {
|
||||
rw.orm = {Schema: exports.Schema, AbstractClass: exports.AbstractClass};
|
||||
|
|
|
@ -145,6 +145,8 @@ function filtering(res, model, filter, instance) {
|
|||
exports.initialize = function(schema, callback) {
|
||||
if (!cradle) return;
|
||||
|
||||
// when using cradle if we dont wait for the schema to be connected, the models fails to load correctly.
|
||||
schema.waitForConnect = true;
|
||||
if (!schema.settings.url) {
|
||||
var host = schema.settings.host || 'localhost';
|
||||
var port = schema.settings.port || '5984';
|
||||
|
|
|
@ -49,8 +49,31 @@ module.exports = function init(root) {
|
|||
|
||||
var schema = new Schema(config && config.driver || 'memory', config);
|
||||
schema.log = log;
|
||||
// when using cradle if we dont wait for the schema to be connected, the models fails to load correctly.
|
||||
|
||||
if (schema.waitForConnect) {
|
||||
schema.on('connected', function() {
|
||||
loadSchema(schema, railway, app, models);
|
||||
});
|
||||
} else {
|
||||
loadSchema(schema, railway, app, models);
|
||||
}
|
||||
|
||||
// check validations and display warning
|
||||
|
||||
var displayWarning = false;
|
||||
Object.keys(models).forEach(function (model) {
|
||||
var Model = models[model];
|
||||
if (Model._validations) {
|
||||
displayWarning = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (displayWarning) {
|
||||
var $ = railway.utils.stylize.$;
|
||||
// require('util').puts($('WARNING:').bold.red + ' ' + $('I can see that you\'ve added validation to db/schema.js. However schema.js file is only used to describe database schema. Therefore validations configured in db/schema.js will be ignored.\nFor business logic (incl. validations) please create models as separate .js files here: app/models/*.js').yellow);
|
||||
}
|
||||
|
||||
function loadSchema(schema, railway, app, models) {
|
||||
railway.orm._schemas.push(schema);
|
||||
|
||||
var context = prepareContext(models, railway, app, schema);
|
||||
|
@ -78,21 +101,6 @@ module.exports = function init(root) {
|
|||
railway.orm._schemas.forEach(function (schema) {
|
||||
schema.freeze();
|
||||
});
|
||||
});
|
||||
|
||||
// check validations and display warning
|
||||
|
||||
var displayWarning = false;
|
||||
Object.keys(models).forEach(function (model) {
|
||||
var Model = models[model];
|
||||
if (Model._validations) {
|
||||
displayWarning = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (displayWarning) {
|
||||
var $ = railway.utils.stylize.$;
|
||||
// require('util').puts($('WARNING:').bold.red + ' ' + $('I can see that you\'ve added validation to db/schema.js. However schema.js file is only used to describe database schema. Therefore validations configured in db/schema.js will be ignored.\nFor business logic (incl. validations) please create models as separate .js files here: app/models/*.js').yellow);
|
||||
}
|
||||
|
||||
function log(str, startTime) {
|
||||
|
@ -201,6 +209,15 @@ function prepareContext(models, railway, app, defSchema, done) {
|
|||
if (cname) settings[cname].table = name;
|
||||
};
|
||||
|
||||
/**
|
||||
* If the Schema has additional types, add them to the context
|
||||
* e.g. MySQL has an additional Point type
|
||||
*/
|
||||
if (Schema.types && Object.keys(Schema.types).length) {
|
||||
for (var typeName in Schema.types) {
|
||||
ctx[typeName] = Schema.types[typeName];
|
||||
}
|
||||
}
|
||||
ctx.Text = Schema.Text;
|
||||
|
||||
return ctx;
|
||||
|
|
Loading…
Reference in New Issue