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

relational-schema-normalization

v3.0.4

Published

This library provides tools for working with **functional dependencies** and **relational schemas** in database theory. It supports common operations such as determining closures, decomposing functional dependencies, and checking for normalization forms l

Downloads

1,135

Readme

Functional Dependencies and Relational Schemas Library

This library provides tools for working with functional dependencies and relational schemas in database theory. It supports common operations such as determining closures, decomposing functional dependencies, and checking for normalization forms like 3NF and BCNF.

Installation

npm  install  relational-schema-normalization

Usage

Functional Dependency Class

The FunctionalDependency class represents a functional dependency in a relational database.

Example:

import { FunctionalDependency } from 'relational-schema-normalization';

const determinant = new Set(['A']);
const dependent = new Set(['B', 'C']);

const fd = new FunctionalDependency(determinant, dependent);

console.log(fd.determinant); // Set { 'A' }
console.log(fd.dependent);   // Set { 'B', 'C' }

Methods

  • equals(fd: FunctionalDependency): boolean: Compares two functional dependencies for equality.
  • decompose(): FunctionalDependency[]: Decomposes a functional dependency with multiple dependents into multiple functional dependencies, each with one dependent.

Functional Dependency Set Class

The FunctionalDependencySet class is a collection of FunctionalDependency objects with operations for union, comparison, and manipulation.

Example

import { FunctionalDependency, FunctionalDependencySet } from 'relational-schema-normalization';

const fd1 = new FunctionalDependency(new Set(['A']), new Set(['B']));
const fd2 = new FunctionalDependency(new Set(['B']), new Set(['C']));
const fdSet = new FunctionalDependencySet([fd1, fd2]);

console.log(fdSet.size());  // 2
console.log(fdSet.contains(fd1));  // true` 

Methods

  • add(fd: FunctionalDependency): boolean: Adds a functional dependency to the set.
  • union(otherFds: FunctionalDependencySet): FunctionalDependencySet: Returns the union of two functional dependency sets.
  • remove(fd: FunctionalDependency): FunctionalDependencySet: Removes a functional dependency from the set.
  • isSubsetOf(otherFds: FunctionalDependencySet): boolean: Checks if the set is a subset of another functional dependency set.

Relational Schema Class

The RelationalSchema class represents a relational schema, which is a set of attributes.

Example

import { RelationalSchema } from 'relational-schema-normalization';

const relationalSchema = new RelationalSchema(['A', 'B', 'C']);
console.log(relationalSchema.attributes);  // Set { 'A', 'B', 'C' }` 

Methods

  • equals(rs: RelationalSchema): boolean: Compares two relational schemas for equality.

Utils Class

The Utils class provides various utility methods for computing closures, decomposing relations, and testing normalization forms.

Public Methods

  1. closureOfSetOfFunctionalDependenciesUsingAttributesClosure(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): FunctionalDependencySet

    • Description: Computes the closure of a set of functional dependencies using attributes closure for a given relational schema and functional dependencies.
  2. closureOfSetOfFunctionalDependencies(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): FunctionalDependencySet

    • Description: Computes the closure of a set of functional dependencies for a given relational schema and set of functional dependencies (slower method).
  3. closureOfSetOfAttributes(alpha: Set<string>, fds: FunctionalDependencySet): Set<string>

    • Description: Computes the closure of a set of attributes for a given set of functional dependencies.
  4. computeMinimalCover(fdsParam: FunctionalDependencySet): FunctionalDependencySet

    • Description: Computes the minimal cover of a set of functional dependencies.
  5. computeCandidateKeys(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): Set<string>[]

    • Description: Computes the candidate keys for a given relational schema and set of functional dependencies.
  6. syntesisAlgorithmFor3NF(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): RelationalSchema[]

    • Description: Decomposes a relational schema into into 3NF (Third Normal Form).
  7. bcnfDecomposition(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): RelationalSchema[]

    • Description: Decomposes a relational schema into BCNF (Boyce-Codd Normal Form).
  8. removeRedundantRelationalSchemas(relationalSchemasParam: RelationalSchema[]): RelationalSchema[]

    • Description: Removes redundant relational schemas from the decomposition result.
  9. extractFunctionalDependenciesForSchema(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): FunctionalDependencySet

    • Description: Extracts the functional dependencies for a given relational schema.
  10. isSchemaIn3NF(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): boolean

    • Description: Checks whether a relational schema is in 3NF (Third Normal Form).
  11. isSchemaInBNCF(relationalSchemaParam: RelationalSchema, fdsParam: FunctionalDependencySet): boolean

    • Description: Checks whether a relational schema is in BCNF (Boyce-Codd Normal Form).
  12. removeExtraneousAttributes(fdParam: FunctionalDependency, fdsParam: FunctionalDependencySet): FunctionalDependencySet

    • Description: Removes extraneous attributes from a functional dependency.
  13. decomposeFunctionalDependencies(fds: FunctionalDependencySet): FunctionalDependencySet

    • Description: Decomposes each functional dependency that has multiple attributes on the right-hand side into single-attribute dependencies.
  14. areSetOfAttributesEqual(s1: Set<string>, s2: Set<string>): boolean

    • Description: Compares two sets of attributes for equality.
  15. areSetsOfAttributesEqual(s1: Set<string>[], s2: Set<string>[]): boolean

    • Description: Compares two array of sets of attributes for equality.

Example: BCNF Decomposition

import { Utils, RelationalSchema, FunctionalDependencySet } from 'relational-schema-normalization';

const relationalSchema = new RelationalSchema(['A', 'B', 'C', 'D']);
const fds = new FunctionalDependencySet([
  new FunctionalDependency(new Set(['A']), new Set(['B'])),
  new FunctionalDependency(new Set(['B']), new Set(['C'])),
]);

const bcnf = Utils.bcnfDecomposition(relationalSchema, fds);
console.log(bcnf);  // Array of RelationalSchema objects after BCNF decomposition` 

License

MIT