Permalink
Browse files

Revert "added; magic collection allocation"

This reverts commit 688c8df.

Several edge cases and doesn't support `use.adHocDb`.
Possibly reintroduce after api is more stable.
  • Loading branch information...
1 parent e7e6b88 commit e15d74317484a1606f6035c29696c22541ad0619 @aheckmann committed Jan 28, 2013
Showing with 1 addition and 92 deletions.
  1. +1 −92 lib/term.js
View
@@ -1,32 +1,11 @@
-/**
- * Dependencies
- */
-
var repl = require('repl')
-var vm = require('vm')
var log = require('./log')
-var debug = require('./debug')
-
-/**
- * If we are using global context for scripts
- */
-
-var GLOBAL = true;
-
-/**
- * REPL creator
- */
module.exports = exports = function (db) {
// start off with an empty prompt so start up logging/debug msgs
// are written without interuption
- var term = repl.start({
- prompt: ''
- , eval: eval_
- , useGlobal: GLOBAL
- , ignoreUndefined: true
- })
+ var term = repl.start('', null, null, true, true);
// overwrite the empty prompt line
process.stdout.write('\x1b[1A\r\n');
@@ -39,73 +18,3 @@ module.exports = exports = function (db) {
return term;
}
-
-/**
- * custom eval for detecting dynamic collection creation
- */
-
-function eval_ (code, context, file, cb) {
- var err, res;
- try {
- if (GLOBAL) {
- res = vm.runInThisContext(code, file);
- } else {
- res = vm.runInNewContext(code, context, file);
- }
- } catch (e) {
- var attempt = tryHandleCollectionAccess(code, e, context, file);
- if (attempt.failed) {
- err = e;
- } else {
- res = attempt.success;
- }
- }
-
- return cb
- ? cb(err, res)
- : [err, res]
-}
-
-/**
- * Determine if the error is due to accessing a
- * non-existent collection. If so, create the collection
- * and re-execute origina code.
- */
-
-function tryHandleCollectionAccess (code, err, context, file) {
- debug('checking for dynamic collection creation');
-
- var missing = /Cannot call method '([^']+)' of undefined/.exec(err);
- if (!missing) {
- return { failed: true }
- }
-
- // check if the method being accessed was on a collection
- var method = missing[1];
- var rgx = new RegExp('\\bdb\\s*\\.([^\\.]+)\\.\\s*' + method + '\\s*\\(')
- var collection = rgx.exec(code);
- if (!collection) {
- debug('dynamic collection was not attempted')
- return { failed: true }
- }
-
- collection = collection[1].trim();
- debug('creating collection: "' + collection + '"');
-
- var out = eval_('(db.collection("' + collection +'"))', context, file)
- if (out[0]) {
- debug('collection creation failed', out[0]);
- return { failed: true }
- }
-
- // we created the collection, re-execute the original code
- debug('re-attempting original code..')
- var out = eval_(code, context, file)
- if (out[0]) {
- debug('re-attempt failed', out[0]);
- return { failed: true }
- }
-
- return { success: out[1] }
-}
-

0 comments on commit e15d743

Please sign in to comment.