Node.js implementation of the Melian protocol. Provides an async API for fetching rows by table/index IDs and decoding the binary row payload.
npm installimport { MelianClient } from './src/MelianClient.js';
const client = await MelianClient.create({ dsn: 'unix:///tmp/melian.sock' });
// Slightly slower, but friendlier
const row = await client.fetchByIntFrom('people', 'id', 5);
const row = await client.fetchByStringFrom('cats', 'name', 'Pixel');
console.log(row.id);
// Slightly faster, using IDs we resolve beforehand (and then store somewhere)
const { tableId, indexId } = client.resolveIndex('table2', 'hostname');
const row = await client.fetchByString(tableId, indexId, Buffer.from('host-00042'));
console.log(row);
// If you need field types, use the *WithFields variants:
const typed = await client.fetchByStringWithFields(tableId, indexId, Buffer.from('host-00042'));
console.log(typed.id.type, typed.id.value);
await client.close();Initialization options (pass to create):
dsn:unix:///pathortcp://host:port(defaults to/tmp/melian.sock).timeout: socket timeout in milliseconds (default 1000).schema: prebuilt schema object.schemaSpec: inline schema spec string (table#id|period|col#idx:type).schemaFile: JSON schema file path.decodeUtf8: decode BYTES fields as UTF-8 strings (default false).
If no schema option is provided, the client issues a DESCRIBE action on first
connection.
Binary payload decoding returns native values by default. If you use the
*WithFields methods, you get an object of fields in the form
{ field: { type, value } } with these mappings:
- NULL:
null - INT64:
BigInt - FLOAT64:
Number - DECIMAL: string
- BOOL: boolean
- BYTES:
BufferunlessdecodeUtf8is enabled, in which case it returns a string.
The test suite assumes a running Melian server (change DSN via
MELIAN_TEST_DSN).
npm install
MELIAN_TEST_DSN="unix:///tmp/melian.sock" npm test