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

knot-db

v1.1.12

Published

Relationship driven No-SQL database

Downloads

25

Readme

KnotDatabase


Get started

Installation

Run the following command to install the package

npm install -g knot-db

Then to start the database, you can simply run :

knot-db

The database should now be running on the port specified in the config.json file. (9600 by default)

Sending queries

To query the database, simply send an HTTP post request at localhost:<PORT>/query with a body like the following :

POST/query
{
    "table" : "employees",
    "query" : "MATCH (a:Person {name: 'Marc'}) RETURN a;"
}

where table is the name of the table to apply the query and query is the actual query to execute.

A typical response would like this :

{
    "a": {
        "P256": {
            "id": "P256",
            "type": "Person",
            "attributes": {
                "name": "Marc",
                "surname": "Davis",
                "sector": "Marketing"
            },
            "relationships": {
                "likes": ["P965"]
            }
        },
        "P443": {
            "id": "P443",
            "type": "Person",
            "attributes": {
                "name": "Marc",
                "surname": "Jones",
                "sector": "Sales",
                "intern": true
            },
            "relationships": {}
        }
    }
}

Insert query

// Adds a node 'P001' of type 'Person' with name 'John Doe' who owns node 'B001'.
INSERT (P001:Person {name: 'John Doe'} {owns: ['B001']});

Valid Formats:

  • INSERT ( Id : Type ) ;
  • INSERT ( Id : Type { Attributes } ) ;
  • INSERT ( Id : Type { Attributes } { Relations } ) ;

Id: Id of the node. Must be unique.
Upper or lower camelcase format required.

Type: Type of the node.
Upper or lower camelcase format required.

Attributes: Attributes of the node.
JSON format required.

Relations: Relations of the node.
JSON format required.

Examples:

// Inserts a node with id '10001' of type 'Person'.
INSERT (10001:Person);

// Inserts a node with id '10001' of type 'Person' with name 'Paul Jones'.
INSERT (10001:Person {name: 'Paul Jones'});

// Inserts a node with id '10001' of type 'Person' with name 'Paul Jones' who likes another node with id '10003'.
INSERT (10001:Person {name: 'Paul Jones'} {likes: ['10003']});

Insert Example

INSERT (P002:Person {name: 'Paul Jones', alive: true, geolocation: [12;23;true;'Québec']} {likes: ['P001'], owns: ['B001';'B002']});
{
    "P002": {
        "id": "P002",
        "type": "Person",
        "attributes": {
            "name": "Paul Jones",
            "alive": true,
            "geolocation": [
                12,
                23,
                true,
                "Québec"
            ]
        },
        "relationships": {
            "likes": ["P001"],
            "owns": ["B001","B002"]
        }
}

Match query

// Matches all persons from 'Canada' who owns a library.
MATCH (a:Person {origin: 'Canada'})=[owns]>(b:Building {type: 'library'}) RETURN a;

Node Selectors

Valid Formats:

  • MATCH ( Name ) ...
  • MATCH ( Name : Type ) ...
  • MATCH ( Name : Type { Criterias } ) ...

Name: Name of the selector. This value is used to identify the selector.
Upper or lower camelcase format required.

Type: Type of the selector. This value is used to filter using the node type.
You can also use the wildcard operator (?) to match any type of node.
Upper or lower camelcase format required.

Criterias: Criterias for selection. This value will be used to filter using the node attributes.
JSON format required.

Examples:

// Match all of any type
MATCH (a) RETURN a;

// Match all of type 'Person'
MATCH (a:Person) RETURN a;

// Match all of type 'Person' with name 'John Doe'
MATCH (a:Person {name: 'John Doe'}) RETURN a;

// Match all of any type with location 'Québec, Canada'
MATCH (a:? {location: 'Québec, Canada'}) RETURN a;

Node Relations

Valid Formats:

  • MATCH SourceSelector =[ Name ]> TargetSelector ...
  • MATCH TargetSelector <[ Name ]= SourceSelector ...

SourceSelector: Source node selector.
See NodeSelectors section above for more details.

Name: Name of the relation. This will be used to filter with the node relationships.
Upper or lower camelcase format required.

TargetSelector: Target node selector.
See NodeSelectors section above for more details.

Examples:

// Match all of type 'Person' type who 'likes' another 'Person'.
MATCH (a:Person)=[likes]>(b:Person) RETURN a;

// Match all of type 'Building' type who are owned by a 'Person'.
MATCH (a:Building)<[owns]=(b:Person) RETURN a;

// Match all of type 'Person' type who 'likes' another 'Person' who owns a 'Building'.
MATCH (a:Person)=[likes]>(b:Person)=[owns]>(c:Building) RETURN a;

Returns Statements

Valid Formats:

  • MATCH ... RETURN Values ;

Values: Return values. If there is more than one return value, values are separated by a comma.
Values must be equal to one of the NodeSelectors Name to be valid.

Examples:

// Returns the dataset with the selector name 'a'.
MATCH (a:Person) RETURN a;

// Returns the datasets with the selector names 'a' and 'b'.
MATCH (a:Person)=[owns]>(b:Building) RETURN a,b;

Update query

// Update name of node 'P001' to value 'John Doe'
UPDATE (P001:Person => {name: 'John Doe'});

Valid Formats:

  • UPDATE ( Id : Type => { UpdateValue } ) ;
  • UPDATE ( ? : Type => { UpdateValue } ) ;
  • UPDATE ( ? : Type { Criterias } => { UpdateValue } ) ;

Id: Id of the selector. If the value is '?', the query will update all nodes of fitting the Type and Criterias.
Upper or lower camelcase format required.

Type: Type of the selector. This value is used to filter with the node type.
Upper or lower camelcase format required.

Criterias: Criterias for selection. This value will be used to filter with the node attributes.
JSON format required.

UpdateValue: Properties of the node to update.
JSON format required.

Examples:

// Updates name of node 'P001' to value 'Paul Jones'.
UPDATE (P001:Person => {name: 'Paul Jones'});

// Updates name of all nodes of type 'Person' to value 'Paul Jones'.
UPDATE (?:Person => {name: 'Paul Jones'});

// Updates name of all nodes of type 'Person' with name 'Marie Jones' to value 'Paul Jones'.
UPDATE (?:Person {name: 'Marie Jones'} => {name: 'Paul Jones'});