1.1.6 • Published 8 months ago

jkdb v1.1.6

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

jkdb

npm.io

A zero dependency javascript Node.js package to interface with kdb+/q (v2.6+).

Installation

npm install --save-dev jkdb

Quick Start

Connect to a q Process

const { QConnection } = require("jkdb");
const q = new QConnection({ port: 1800 });
q.connect((err) => {
  if (err) throw err;
  console.log("connected");
  // send query from here
});

Connect to a TLS-protected q Process

const { QConnection } = require("jkdb");
const q = new QConnection({ port: 1800, useTLS: true });
q.connect((err) => {
  if (err) throw err;
  console.log("connected");
  // send query from here
});

Connect to a q Process with Credentials

const { QConnection } = require("jkdb");
const q = new QConnection({ port: 1800, user: "user", password: "password" });
q.connect((err) => {
  if (err) throw err;
  console.log("connected");
  // send query from here
});

Send a Sync Query

q.sync("(+/) til 10", (err, res) => {
  if (err) throw err;
  console.log("result: ", res);
  // result: 45
});

Send a Sync Function Call

q.sync(["(*/)", [22, 27, 45]], (err, res) => {
  if (err) throw err;
  console.log("result: ", res);
  // result: 26730
});

Send a Sync Function Call with Multiple Parameters

q.sync(
  [
    "mmu",
    [1, 2, 3],
    [
      [1, 2, 3],
      [4, 5, 6],
      [7, 8, 9],
    ],
  ],
  (err, res) => {
    if (err) throw err;
    console.log("result: ", res);
    // result: 30,36,42
  }
);

Send an Async Query

q.asyn("show 99", (err) => {
  if (err) throw err;
});

Send an Async Function Call

q.asyn(["show", 99], (err) => {
  if (err) throw err;
});

Subscribe

q.on("upd", (table, data) => {
  console.log(table, data);
});

q.sync(".u.sub[`trade;`7203.T]", (err, _res) => {
  if (err) throw err;
});

Close q Connection

q.close(() => {
  console.log("closed");
});

Date Types

Deserialization

Deserialization of long and timestamp can be controlled by QConnection arguments useBigInt and includeNanosecond.

k typeargumentjavascript typek nullinfinity-infinity
booleanBoolean
guidString00000000000000000000000000000000
byteNumber
shortNumberNaNInfinity-Infinity
intNumberNaNInfinity-Infinity
longNumberNaNInfinity-Infinity
longuseBigIntBigIntNaNInfinity-Infinity
realNumberNaNInfinity-Infinity
floatNumberNaNInfinity-Infinity
charString' '
symbolString''
timestampDatenullnullnull
timestampincludeNanosecondString''''''
monthStringnullnullnull
dateDatenullnullnull
datedateToMillisecondNumberNaNInfinity-Infinity
datetimeDatenullnullnull
datetimedateToMillisecondNumberNaNInfinity-Infinity
timespanStringnullnullnull
minuteStringnullnullnull
secondStringnullnullnull
timeStringnullnullnull
dictObject
listArray
tableObject
lambdaString
projectionArray

Serialization

Atom

javascript typek type
Booleanboolean
Numberfloat
Stringchars
Datetimestamp

Array

javascript typeSymbol.for('kType')k type
Boolean Arraybboolean
String Arraygguid
Number Arrayiint
Number Arrayjlong
Number Arrayffloat
String Arraycchar
String Arrayssymbol
Date Arrayptimestamp
Date Arrayddate
Date Arrayzdatetime

Use Symbol.for('kType') to specify k type for the array, e.g.

const ints = [99, 11, 3, 3];
ints[Symbol.for("kType")] = "j";

Object without meta

Convert to a dictionary, keys are symbols, e.g.

const dict = { sym: "8306.T", price: 668.2 };

Object with meta

Convert to a table, e.g.

const table = {
  sym: ["AXJO", "AXJO"],
  date: [new Date("2021-05-13"), new Date("2021-05-14")],
  open: [7000, 6000],
};
table[Symbol.for("meta")] = {
  c: ["sym", "date", "open"],
  t: ["s", "d", "f"],
};
1.1.6

8 months ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago