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

@noamzuck/d-base

v1.0.2

Published

This package helps you manage databases in the most convenient way with the use of functions to create, delete, update, write, search and more.

Downloads

6

Readme

Installation

Use the package manager npm to install d-base.

npm install @noamzuck/d-base

Usage

A simple example of how to create a database

//import the package as the "dbase" variable
const dbase = require('@noamzuck/d-base');

//sets the path to the folder "/d-base/"
dbase.setPath("d-base");

//creates a new database named "first" with the subjects "name", "age" and "city"
await dbase.create({ name: "first", subjects: ["name", "age", "city"], description: "example" });

A more complicated example to use the whole d-base functions

//import the package as the "dbase" variable
const dbase = require('@noamzuck/d-base');

//creates a custom function to initialize a database
async function initializeDatabase() {
    //sets the path to the folder "/d-base/" (this is the default path)
    console.log(dbase.setPath("d-base"));
    
    //checks if the database already exists
    await dbase.check({name: "first"})
    .then(async check => {
        if(!check) {
            //creates a new database named "first" with the subjects "name", "age" and "city"
            console.log(await dbase.create({ name: "first", subjects: ["name", "age", "city"], description: "example" }));
        } else {
            console.log("The database already exists.");
        }
    });

    //sets new rows in the database
    console.log(await dbase.set({name: "first", data: { name: "Joe", age: 20, city: "Philadelphia"}}));
    console.log(await dbase.set({name: "first", data: { name: "Josh", age: 25, city: "New York"}}));
    console.log(await dbase.set({name: "first", data: { name: "Dave", age: 27, city: "Los Angeles"}}));

    //gets the contents of the database named "first"
    console.log(await dbase.get({name: "first"}));

    //gets a random id of a row from the database
    const random = await dbase.getARandomRow({name: "first"});

    //gets the contents of the row from the database
    console.log(await dbase.get({name: "first", id: random}));

    //gets the contents of a specific cell
    console.log(await dbase.get({name: "first", id: random, subject: "name"}));
    
    //updates a specific cell
    console.log(await dbase.update({name: "first", id: random, data: "Mike", subject: "name" }));
    
    //updates a specific row
    console.log(await dbase.update({name: "first", id: random, data: { name: "Mike", age: 11 } }));
    
    //updates a specific database details
    console.log(await dbase.updateDatabase({name: "first", newName: "third", description: "one two three"}));

    //duplicates a specific database
    console.log(await dbase.duplicate({name: "first", newName: "second" }));

    //removes a specific database
    console.log(await dbase.remove({name: "second"}));

    //checks if the row exists
    console.log(await dbase.check({name: "third", id: random}));

    //removes the previous row
    console.log(await dbase.remove({name: "third", id: random}));
    
    //checks again if the row exists
    console.log(await dbase.check({name: "third", id: random}));

    //trying to find the string "Jo" in the database under the subject "name" 
    console.log(await dbase.find({name: "third", subject: "name", content: "Jo", exact: false}));

    //trying to find the exact string "Joe" in the database under the subject "name" 
    console.log(await dbase.find({name: "third", subject: "name", content: "Joe"}));
}

//runs the function "initializeDatabase"
initializeDatabase()
.then(() => {
    //put here your code
})
.catch(console.error);

Documentation

setPath

The function defines a new path to the directory's databases (default: /d-base/).

| Parameter | Type | Example | |-----------|------------|---------| | path | string | "test" |

create

The function creates a new database.

| Parameter | Type | Example | |-----------------|--------------------------|----------------------------------------| | name | string | "name" | | subjects | array | ["subject", "subject"] | | description | string | Optional. "description" |

set

The function sets a row in the database.

| Parameter | Type | Example | |------------|-----------------------|----------------------------------------------| | name | string | "name" | | data | json | { subject: "content", subject: "content" } |

get

The function gets a database or a specific row or cell in the database.

| Parameter | Type | Example | |------------|---------------|-------------| | name | string | "name" | | id | string | Optional. "a1b2c3d4" | | subject | string | Optional. "subject" |

update

The function updates a specific row or cell in the database.

| Parameter | Type | Example | |------------|-----------------------------------------------------|----------------------------------------------| | name | string | "name" | | id | string | "a1b2c3d4" | | data | json / string | Optional. { subject: "content", subject: "content" } / "example" | | subject | string | Optional. "subject" |

updateDatabase

The function updates a database.

| Parameter | Type | Example | |--------------|--------------------------|----------------------------------------| | name | string | "name" | | newName | string | Optional. "newName" | | subjects | array | Optional. ["subject", "subject"] | | description| string | Optional. "description" |

remove

The function removes a specific row or an entire database.

| Parameter | Type | Example | |------------|---------------|-------------| | name | string | "name" | | id | string | Optional. "a1b2c3d4" |

check

The function checks if a specific row or database exists.

| Parameter | Type | Example | |------------|---------------|-------------| | name | string | "name" | | id | string | Optional. "a1b2c3d4" |

find

The function finds content in the database.

| Parameter | Type | Example | |------------|---------------|-------------| | name | string | "name" | | subject | string | "subject" | | content | allTypes | any | | exact | bool | Optional. true |

duplicate

The function duplicates an existing database.

| Parameter | Type | Example | |------------|---------------|-------------| | name | string | "name" | | newName | string | "newName" |

getARandomRow

The function returns an id of a random row from a database.

| Parameter | Type | Example | |------------|---------------|-------------| | name | string | "name" |

Contributors