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

rljson

v3.0.8

Published

Define and manage relational data structures in JSON

Downloads

909

Readme

rljson

rljson: Define and manage relational data structures in JSON

rljson

Motivation

Relational data structures are foundational for representing complex relationships between entities, but traditional relational databases often require heavy frameworks or specific query languages. By defining relational data structures in JSON, developers gain the flexibility to work with structured and interconnected data in a lightweight, human-readable format that's widely supported across platforms and programming environments. rljson simplifies data exchange in APIs, enhances compatibility with SQL and NoSQL databases, and supports use cases where lightweight data representation is crucial, all while preserving the benefits of relational modeling.

Features

  • Define independent or interconnected tables
  • Link and access fields across tables
  • Deep 128bit hashing
  • Immutable state
  • No duplicates through hashes

Example

import { JsonHash } from 'gg-json-hash';
import { Rljson } from 'rljson';

const jh = JsonHash.default;

// .............................................................
console.log('Create tables');

let db = Rljson.fromJson({
  tableA: {
    _data: [{ a: 'a0' }, { a: 'a1' }],
  },
  tableB: {
    _data: [{ b: 'b0' }, { b: 'b1' }],
  },
});

// .............................................................
console.log('Each item in the table gets an content based hash code');

const hashA0 = db.hash({ table: 'tableA', index: 0 });
const hashA1 = db.hash({ table: 'tableA', index: 1 });
const hashB0 = db.hash({ table: 'tableB', index: 0 });
const hashB1 = db.hash({ table: 'tableB', index: 1 });

// .............................................................
console.log('The hashcode can be used to access data');
const a0 = db.get({ table: 'tableA', item: hashA0, key1: 'a' });
console.log(a0); // a0

const a1 = db.get({ table: 'tableA', item: hashA1, key1: 'a' });
console.log(a1); // a1

const b0 = db.get({ table: 'tableB', item: hashB0, key1: 'b' });
console.log(b0); // b0

const b1 = db.get({ table: 'tableB', item: hashB1, key1: 'b' });
console.log(b1); // b1

// .............................................................
console.log('Add and merge additional data. The original table is not changed');

db = db.addData({
  tableA: {
    _data: [{ a: 'a2' }],
  },
  tableB: {
    _data: [{ b: 'b2' }],
  },
  tableC: {
    _data: [{ c: 'c0' }],
  },
});

// .............................................................
console.log('Print a list of all values in the database');
const allPaths = db.ls();
console.log(allPaths.map((path) => `- ${path}`).join('\n'));

// .............................................................
console.log('Create interconnected tables');

db = Rljson.fromJson({
  a: {
    _data: [
      {
        value: 'a',
      },
    ],
  },
});

const tableAValueHash = db.hash({ table: 'a', index: 0 });

db = db.addData({
  b: {
    _data: [
      {
        aRef: tableAValueHash,
      },
    ],
  },
});

const tableBValueHash = db.hash({ table: 'b', index: 0 });

// .............................................................
console.log('Join tables when reading values');

const a = db.get({
  table: 'b',
  item: tableBValueHash,
  key1: 'aRef',
  key2: 'value',
});

console.log(a); // a

// .............................................................
console.log('To hash data in advance use gg_json_hash');
const hashedData = jh.apply({
  tableA: {
    _data: [{ a: 'a0' }, { a: 'a1' }],
  },
});

console.log('Validate hashes when adding data');
db = Rljson.fromJson(hashedData, { validateHashes: true });

Contribute

Contributions are welcome! To contribute:

  • Fork the repository on GitHub.
  • Make your changes in your forked repository.
  • Submit a pull request to the main branch of this repository.
  • Thank you for helping improve this package! 😊