Discussion (2)3
Log in or sign up to continue

The idea of connecting Node.js to Cache is to write your logic in JavaScript, except for where you need to invoke legacy code.  It makes little sense to invoke COS built-in functions such as $h via cache.node.

With that in mind, have you looked at QEWD.js, which makes the integration of Node.js and Cache very much simpler? See:


To expand the concept of using JavaScript rather than COS as the language for your logic, you might want to take a look at this: https://www.slideshare.net/robtweed/data-persistence-as-a-language-feature

Hi Stephen,

I think the short (and potentially dangerous) answer that you are looking for is to use xecute to run COS provided as an argument, such that you have one generic method, e.g.

var h = foo.get_execute("$h");

where execute implements xecute on the passed argument(s).

It is better to try and understand JavaScripts built in functions then call out to Caché which could end up being expensive.

However, if you wanted to replicate functions to make context switching to JavaScript less of a cognitive load then you could write your own mini function library...

let $piece = (string,delimiter,from,to=from) => {
  return string.split(delimiter).slice(from-1,to).join("~");

let p1 = $piece("hello~world","~",1);
let $extract = (string,from,to=from) => {
    return string.substring(from-1,to);

let sub = $extract("Hello, World",2,5)
let $length = (string,delimiter) => {
  if (delimiter !== undefined) return string.split(delimiter).length;
  return string.length;

let len = $length("Hello, World")

let count = $length("Hello~World","~")

Probably the function of most use is $horolog, I've built a couple of solutions that uses horolog everywhere, but tbh I just use W3C dates and auto convert between the two these days, if your using JSON then the Cogs library will automatically do this for you.

I can't find my original horolog everywhere source code, but here is a quick bash...

let $h = function() {
  let now = new Date();
  return Math.floor(((now.getTime() + 4070908800000) / 86400000)) + "," + ((now.getHours() * 60 * 60) + (now.getMinutes() * 60) + now.getSeconds());

> "64776,60593"
let horologToJSDate = function(h) {
    let parts = h.split(",");
    return new Date(((parts[0] * 86400000) - 4070908800000) + (parts[1] === undefined ? 0 : seconds * 1000))

> Tue May 08 2018 17:58:01 GMT+0100 (GMT Summer Time)

> Tue May 08 2018 01:00:00 GMT+0100 (GMT Summer Time)