l>

documentation

Bun SDK

Connect to an l server from Bun with the @l-labs/bun IPC client.

The Bun SDK talks to a running l server over TCP through a small vendored C connector loaded with bun:ffi.

l-labs/bun_ipc

Install

Start an l server, then install dependencies in your Bun project:

l -p 5001
bun install

First query

import { LConnection, I, vF, vI, vS } from "@l-labs/bun";

const conn = LConnection.connect("localhost", 5001);
conn.execute("1+1"); // 2
conn.execute("sum", vI(1, 2, 3)); // 6
conn.execute("trade:([]sym:`A`B;price:1.5 2.5)");
conn.execute("select from trade where price>2"); // [{sym:"B", ...}]
conn.set("xs", vF(1.5, 2.5));
conn.close();

Calls are synchronous. Server errors throw Error, and the connection stays usable.

For exact wire types, use the generator functions:

ShapeGenerators
AtomsB G H I J E F C S D T Z
VectorsvG vH vI vJ vE vF vS vD vT vZ
Char vectorvC(string)

Quickstart example

This example connects, queries, passes typed arguments, and sets a table from Bun-side vectors:

import { LConnection, I, vF, vI, vS } from "@l-labs/bun";

const port = parseInt(process.env.L_TEST_PORT || "5001");
const conn = LConnection.connect("localhost", port);

console.log(conn.execute("1+1")); // 2
console.log(conn.execute("til 10")); // [0, 1, ..., 9]

conn.execute("trade:([]sym:`IBM`MSFT`AAPL;price:120.5 340.2 175.8)");
console.log(conn.execute("select from trade where price > 200"));
// [{ sym: "MSFT", price: 340.2 }]

console.log(conn.execute("sum", vI(1, 2, 3, 4, 5))); // 15
console.log(conn.execute("{x+y}", I(10), I(32))); // 42

conn.set("t", {
  sym: vS("IBM", "MSFT", "AAPL"),
  price: vF(120.5, 340.2, 175.8),
  qty: vI(100, 200, 300),
});
conn.execute("t: flip t");
console.table(conn.execute("select sym, price from t"));

conn.close();

Type mapping

l typeTagJavaScript
boolean1boolean
byte, short, int, long4-7number
real, float8, 9number
char vector, symbol10, 11string
timestamp, timespan12, 16number raw i64 ns
month, minute, second, time13, 17-19number raw count
date, datetime14, 15Date
mixed list0any[]
table98array of row objects
dict99object or key/value pairs

Plain JavaScript arguments convert the other way: numbers become int or float atoms, strings become symbols, arrays become vectors, objects become dicts, and booleans and dates map to their matching l values.