Fix scoped find method
This commit is contained in:
parent
5c2b995cf1
commit
40b4d28a1a
|
@ -760,7 +760,7 @@ function defineScope(cls, targetClass, name, params, methods) {
|
||||||
f.create = create;
|
f.create = create;
|
||||||
f.destroyAll = destroyAll;
|
f.destroyAll = destroyAll;
|
||||||
for (var i in methods) {
|
for (var i in methods) {
|
||||||
f[i] = methods;
|
f[i] = methods[i].bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// define sub-scopes
|
// define sub-scopes
|
||||||
|
|
|
@ -35,7 +35,7 @@ if (path.existsSync(schemaFile + 'js')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schemaFile) {
|
if (schemaFile) {
|
||||||
runCode(schemaFile, context);
|
railway.utils.runCode(schemaFile, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// and freeze schemas
|
// and freeze schemas
|
||||||
|
@ -44,9 +44,9 @@ railway.orm._schemas.forEach(function (schema) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function log(str, startTime) {
|
function log(str, startTime) {
|
||||||
var $ = utils.stylize.$;
|
var $ = railway.utils.stylize.$;
|
||||||
var m = Date.now() - startTime;
|
var m = Date.now() - startTime;
|
||||||
utils.debug(str + $(' [' + (m < 10 ? m : $(m).red) + ' ms]').bold);
|
railway.utils.debug(str + $(' [' + (m < 10 ? m : $(m).red) + ' ms]').bold);
|
||||||
app.emit('app-event', {
|
app.emit('app-event', {
|
||||||
type: 'query',
|
type: 'query',
|
||||||
param: str,
|
param: str,
|
||||||
|
@ -54,57 +54,6 @@ function log(str, startTime) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function runCode(filename, context) {
|
|
||||||
var isCoffee = filename.match(/coffee$/);
|
|
||||||
|
|
||||||
context = context || {};
|
|
||||||
|
|
||||||
var dirname = path.dirname(filename);
|
|
||||||
|
|
||||||
// extend context
|
|
||||||
context.require = context.require || function (apath) {
|
|
||||||
var isRelative = apath.match(/^\.\.?\//);
|
|
||||||
return require(isRelative ? path.resolve(dirname, apath) : apath);
|
|
||||||
};
|
|
||||||
context.app = app;
|
|
||||||
context.railway = railway;
|
|
||||||
context.console = console;
|
|
||||||
context.setTimeout = setTimeout;
|
|
||||||
context.setInterval = setInterval;
|
|
||||||
context.clearTimeout = clearTimeout;
|
|
||||||
context.clearInterval = clearInterval;
|
|
||||||
context.__filename = filename;
|
|
||||||
context.__dirname = dirname;
|
|
||||||
context.process = process;
|
|
||||||
context.t = context.t || t;
|
|
||||||
context.Buffer = Buffer;
|
|
||||||
|
|
||||||
var code = path.existsSync(filename) && require('fs').readFileSync(filename).toString();
|
|
||||||
if (!code) return;
|
|
||||||
if (isCoffee) {
|
|
||||||
try {
|
|
||||||
var cs = require('coffee-script');
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error('Please install coffee-script npm package: `npm install coffee-script`');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
code = require('coffee-script').compile(code);
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error in coffee code compilation in file ' + filename);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
var m = require('vm').createScript(code.toString('utf8'), filename);
|
|
||||||
m.runInNewContext(context);
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error while executing ' + filename);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function prepareContext(defSchema, done) {
|
function prepareContext(defSchema, done) {
|
||||||
var ctx = {app: app},
|
var ctx = {app: app},
|
||||||
models = {},
|
models = {},
|
||||||
|
|
|
@ -109,14 +109,13 @@ Schema.Text = Text;
|
||||||
*
|
*
|
||||||
* @example simple case
|
* @example simple case
|
||||||
* ```
|
* ```
|
||||||
* var User = schema.defind('User', {
|
* var User = schema.define('User', {
|
||||||
* email: String,
|
* email: String,
|
||||||
* password: String,
|
* password: String,
|
||||||
* birthDate: Date,
|
* birthDate: Date,
|
||||||
* activated: Boolean
|
* activated: Boolean
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
|
||||||
* @example more advanced case
|
* @example more advanced case
|
||||||
* ```
|
* ```
|
||||||
* var User = schema.defind('User', {
|
* var User = schema.defind('User', {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "jugglingdb",
|
"name": "jugglingdb",
|
||||||
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
|
"description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite",
|
||||||
"version": "0.1.5",
|
"version": "0.1.6",
|
||||||
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
|
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
|
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },
|
||||||
|
|
Loading…
Reference in New Issue