DEV Community

Nivethan
Nivethan

Posted on

A Quick Universe Snippet

This is about the multivalue database, Universe and a node library that I wrote to talk to it. I have an article about installing Universe if anyone wants to try using a more esoteric and weird database than the usual SQL ones :)

A quick snippet to select a file and read in every record. I'm using this to generate a file of ids and their descriptions. Doing this in BASIC would be quite easy as well, it would actually be identical for the most part but I can't catch the output as easily as just running the script with stout pointed to a file.

const mv = require("pick-mv");
const Universe = require("pick-universe");
const uv = new Universe("localhost", "username", "password", "/path/to/account");

uv.StartSession();

const INV = uv.Open("INVENTORY-FILE");
uv.Select(INV);

while (true) {
    let id = uv.ReadNext();
    if (id === null) break;
    let record = mv.MVMatrix(uv.Read(id, INV));
    console.log(id, record[[1]]);
}

uv.EndAllSessions();
Enter fullscreen mode Exit fullscreen mode

The core code in BASIC, line wise, they end up very similar but performance wise, huge difference. I had to run the javascript version for 2 minutes versus the BASIC version that ran in a few seconds.

OPEN "INVENTORY-FILE" TO INV ELSE STOP

SELECT INV

LOOP
    READNEXT ID ELSE ID = ''
WHILE ID # '' DO
    READ RECORD FROM INV, ID ELSE RECORD = ''
REPEAT
Enter fullscreen mode Exit fullscreen mode

It would be worth generating a vim snippet to automatically get hints for the functions. I also need to profile if it's worth doing this readnext in javascript or if its better to do it in C and then do the MVMatrix in javascript land.

Top comments (0)