DEV Community

Nivethan
Nivethan

Posted on

2 2

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.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

SurveyJS custom survey software

JavaScript UI Library for Surveys and Forms

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

View demo

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay