clkao / plv8js-migrated

Automatically exported from code.google.com/p/plv8js
Other
0 stars 0 forks source link

feature: System Information Functions #60

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
pg docs: http://www.postgresql.org/docs/9.2/static/functions-info.html

My use case is I need fast access to txid_current() to implement a cache object 
(global) so plv8 functions can share some state between calls in the same 
transaction.

But, I'm sure other functions will come in handle as well.  Here is some js 
code of what I'm trying to accomplish:

$cache = (function () {
  var bag, bagtx;
  function Cache() {}
  Cache.prototype.get = function (key) {
    // could be a lot faster if plv8 had something like plv8.sys.txid_current() 
    var tx = plv8.execute("select txid_current();")[0].txid_current;
    if (tx !== bagtx) { bag = {}; bagtx = tx; }
    return bag[key];
  };
  Cache.prototype.set = function (key, value) {
    var tx = plv8.execute("select txid_current();")[0].txid_current;
    if (tx !== bagtx) { bag = {}; bagtx = tx; }
    bag[key] = value;
  };
  Cache.prototype.setOnce = function (key, value) {
    // this.get ensures bagtx
    if (this.get(key) || bag.hasOwnProperty(key)) { return; }
    bag[key] = value;
  };
  return new Cache();
}());

Original issue reported on code.google.com by t...@blit.com on 14 Mar 2013 at 9:27

GoogleCodeExporter commented 9 years ago
I personally would like to have extensibility layer such as npm in Node, but 
currently I don't want to include this kind of uses in core of plv8 and keep it 
simple.  Does anyone have better idea?

Original comment by umi.tan...@gmail.com on 9 Apr 2013 at 7:34