Can you "store" javascript in a DB, and then execute it later time?
<p>(please throw any concern for security or anything out the window, as its a internal application)</p>

<p>basically What i want to do is store a javascript function in a db:</p>

<pre><code> function x(name) {
   return name + 1;
 }
</code></pre>

<p>and then at a later time fetch the DB row </p>

<p>(pseudo code here)</p>

<pre><code> x = db.get('function').where('id').equals(1);

 console.log(x('bob'));
 //should print "bob +1 "
</code></pre>

<p>so here is the scenario i am envisioning:</p>

<p>basically, i am getting a JSON object, and depending on certain criteria, i want to do some transformation to that json, and output the new transformed json. for the sake of the "main" app, i dont want to hard code the transformation logic, instead it will be dynamic (dynamic in the sense that a different developer will provide it at run time)</p>

<p>so a DB might contain:</p>

<pre><code>ID   |    javascript 
====================
1    |    (some js code)
2    |    (same func, different code)
</code></pre>

<p>what i want to do is execute that JS code stored in the DB, with an input of my choosing. </p>

<p>if it makes it easier, the function name will be standard.. i.e we can assume that the javascript saved in the DB will all follow:</p>

<pre><code>function transform(input) {
  /* below this line logic will change

* end diff logic/
 return output
}
</code></pre>