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

rdtheory

v0.0.5

Published

a library implementing several algorithms from relational database theory

Downloads

1

Readme

rdtheory -- various tools and algorithms from relational database theory

NPM

Installation

npm install rdtheory

Usage

Closure

You can use rdtheory to find the closure of a set of attributes under (with respect to) a set of functional dependencies:

var Ssn  = new rdtheory.Attribute("Ssn");
var Ename = new rdtheory.Attribute("Ename");
var Pnumber = new rdtheory.Attribute("Pnumber");
var Pname = new rdtheory.Attribute("Pname");
var Plocation = new rdtheory.Attribute("Plocation");
var Hours = new rdtheory.Attribute("Hours");

var a = new rdtheory.FD(Ssn, Ename);
var b = new rdtheory.FD(Pnumber, [Pname, Plocation]);
var c = new rdtheory.FD([Ssn, Pnumber], Hours);

var F = new rdtheory.FDSet([a, b, c]);
var closure =  new rdtheory.AttributeSet([Ssn]).closureUnder(F);
console.log(closure.toString()); // will continue "Ssn" and "Ename"

Coverage testing

You can use rdtheory to test if one set of functional dependencies covers another:

var A = new rdtheory.Attribute("A");
var C = new rdtheory.Attribute("C");
var D = new rdtheory.Attribute("D");
var E = new rdtheory.Attribute("E");
var H = new rdtheory.Attribute("H");

var f1 = new rdtheory.FD(A, C);
var f2 = new rdtheory.FD([A, C], D);
var f3 = new rdtheory.FD(E, [A, D]);
var f4 = new rdtheory.FD(E, H);

var g1 = new rdtheory.FD(A, [C, D]);
var g2 = new rdtheory.FD(E, [A, H]);

var F = new rdtheory.FDSet([f1, f2, f3, f4]);
var G = new rdtheory.FDSet([g1, g2]);

console.log(F.covers(G)) // true
console.log(G.covers(F)) // true

You can also use coverage tests to perform equivalence tests (F is equivelant to G if F covers G and G covers F):

console.log(F.equivalentTo(G)) // true

Minimal covers

You can use rdtheory to find a minimal cover of a set of functional dependencies:

var A = new rdtheory.Attribute("A");
var B = new rdtheory.Attribute("B");
var C = new rdtheory.Attribute("C");
var D = new rdtheory.Attribute("D");
var E = new rdtheory.Attribute("E");

var e1 = new rdtheory.FD(B, A);
var e2 = new rdtheory.FD(D, A);
var e3 = new rdtheory.FD([A, B], D);
E = new rdtheory.FDSet([e1, e2, e3]);

var minCover = E.minimalCover();
console.log(minCover.toString); // will contain B -> D and D -> A

Finding primiary keys

You can use rdtheory to find the primary keys of a relation:

var Name = new rdtheory.Attribute('Name');
var Address = new rdtheory.Attribute('Address');
var Phone = new rdtheory.Attribute('Phone');
var ZipCode = new rdtheory.Attribute('ZIP');

var f1 = new rdtheory.FD(Name, Address);
var f2 = new rdtheory.FD(Name, Phone);
var f3 = new rdtheory.FD(Address, ZipCode);

var attrs = new rdtheory.AttributeSet([Name, Address, Phone, ZipCode]);
var fds = new rdtheory.FDSet([f1, f2, f3]);

var R = new rdtheory.Relation(attrs, fds);
console.log(R.findPossibleKey().toString()); // will be Name

Loseless join and dependency preserving 3NF decomposition

You can use rdtheory to decompose a relation into 3NF:

var Name = new rdtheory.Attribute('Name'); // A
var Address = new rdtheory.Attribute('Address'); // B
var Phone = new rdtheory.Attribute('Phone'); // C
var ZipCode = new rdtheory.Attribute('ZIP'); // D
var Dept = new rdtheory.Attribute('Dept'); // E
var Manager = new rdtheory.Attribute('Manager'); // F
var YearsEmployed = new rdtheory.Attribute('Years'); // G
var Pay = new rdtheory.Attribute('Pay'); // H

var f1 = new rdtheory.FD(Name, [Address, Phone, Dept]);
var f2 = new rdtheory.FD(Dept, Manager);
var f3 = new rdtheory.FD(Address, ZipCode);
var f4 = new rdtheory.FD([Dept, YearsEmployed], Pay);


var attrs = new rdtheory.AttributeSet([Name, Address, Phone, ZipCode, Dept, Manager, YearsEmployed, Pay]);
var fds = new rdtheory.FDSet([f1, f2, f3, f4]);

var R = new rdtheory.Relation(attrs, fds);

var D = R.decomposeTo3NF();
console.log(D.toString()); // the decomposition

Obviously, this isn't very well documented (yet). Here's a demo you can play around with.