Fix scoped find method

This commit is contained in:
Anatoliy Chakkaev 2012-04-07 17:43:15 +04:00
parent 5c2b995cf1
commit 40b4d28a1a
4 changed files with 6 additions and 58 deletions

View File

@ -760,7 +760,7 @@ function defineScope(cls, targetClass, name, params, methods) {
f.create = create;
f.destroyAll = destroyAll;
for (var i in methods) {
f[i] = methods;
f[i] = methods[i].bind(this);
}
// define sub-scopes

View File

@ -35,7 +35,7 @@ if (path.existsSync(schemaFile + 'js')) {
}
if (schemaFile) {
runCode(schemaFile, context);
railway.utils.runCode(schemaFile, context);
}
// and freeze schemas
@ -44,9 +44,9 @@ railway.orm._schemas.forEach(function (schema) {
});
function log(str, startTime) {
var $ = utils.stylize.$;
var $ = railway.utils.stylize.$;
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', {
type: 'query',
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) {
var ctx = {app: app},
models = {},

View File

@ -109,14 +109,13 @@ Schema.Text = Text;
*
* @example simple case
* ```
* var User = schema.defind('User', {
* var User = schema.define('User', {
* email: String,
* password: String,
* birthDate: Date,
* activated: Boolean
* });
* ```
*
* @example more advanced case
* ```
* var User = schema.defind('User', {

View File

@ -1,7 +1,7 @@
{
"name": "jugglingdb",
"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>",
"contributors": [
{ "name": "Anatoliy Chakkaev", "email": "rpm1602@gmail.com" },