npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jkdb

v1.1.6

Published

javascript interface for kdb+/q

Downloads

21

Readme

jkdb

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 type | argument | javascript type | k null | infinity | -infinity | | ---------- | ----------------- | --------------- | -------------------------------- | -------- | --------- | | boolean | | Boolean | | | | | guid | | String | 00000000000000000000000000000000 | | | | byte | | Number | | | | | short | | Number | NaN | Infinity | -Infinity | | int | | Number | NaN | Infinity | -Infinity | | long | | Number | NaN | Infinity | -Infinity | | long | useBigInt | BigInt | NaN | Infinity | -Infinity | | real | | Number | NaN | Infinity | -Infinity | | float | | Number | NaN | Infinity | -Infinity | | char | | String | ' ' | | | | symbol | | String | '' | | | | timestamp | | Date | null | null | null | | timestamp | includeNanosecond | String | '' | '' | '' | | month | | String | null | null | null | | date | | Date | null | null | null | | date | dateToMillisecond | Number | NaN | Infinity | -Infinity | | datetime | | Date | null | null | null | | datetime | dateToMillisecond | Number | NaN | Infinity | -Infinity | | timespan | | String | null | null | null | | minute | | String | null | null | null | | second | | String | null | null | null | | time | | String | null | null | null | | dict | | Object | | | | | list | | Array | | | | | table | | Object | | | | | lambda | | String | | | | | projection | | Array | | | |

Serialization

Atom

| javascript type | k type | | --------------- | --------- | | Boolean | boolean | | Number | float | | String | chars | | Date | timestamp |

Array

| javascript type | Symbol.for('kType') | k type | | --------------- | ------------------- | --------- | | Boolean Array | b | boolean | | String Array | g | guid | | Number Array | i | int | | Number Array | j | long | | Number Array | f | float | | String Array | c | char | | String Array | s | symbol | | Date Array | p | timestamp | | Date Array | d | date | | Date Array | z | datetime |

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"],
};