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

wine-database

v1.3.5

Published

NoSQL database with encryption and easy implementation method

Downloads

21

Readme

Wine DataBase

Installation

npm install wine-database

Usage

const WineDB = require("wine-database");

const db = WineDB.init("name", "password");
db.create({
    name: "test"
});

console.log(db.getAll());

Password is optional, if you do not enter a password, the database will be saved to an unencrypted JSON file.

API Reference

db.getAll()

Returns all elements stored in the database.

db.get(id)

Retrieves an element by its ID.

db.filter(callback)

Filters all elements in the database and returns those that match the requirements specified in the callback function.

db.filter(x => x.age > 18);// Returns users whose age is greater than 18 years

db.find(callback)

Finds and returns the first element that matches the requirements specified in the callback function.

db.find(x => x.age > 18);//Returns the first user whose age is greater than 18 years

db.create(object)

Creates a new object in the database. This method automatically assigns a unique ID to the object, even if the object passed already has an ID (the existing ID will be replaced). The method returns the created object.

db.setOrCreate(object)

Attempts to update an existing object in the database. If the object is not found, it creates a new object. The method returns the created or updated object.

db.set(object)

Updates an existing element in the database and returns the updated element. If no matching element is found, it returns undefined.

db.delete(id)

Deletes an element by its ID.

Advanced Usage

Defining a Class for Database Entries

The defineClass method allows you to define a class to be used for all objects created in the database. This can be useful when you want to enforce a specific structure or behavior for your database entries.

db.defineClass(ClassObject);

Example:

class Wine {
    constructor(props) {
        this.name = props.name;
        this.year = props.year;
    }

    getAge() {
        return new Date().getFullYear() - this.year;
    }
}

db.defineClass(Wine);

const newWine = db.create({ name: "Chardonnay", year: 2018 });
console.log(newWine.getAge()); // Outputs the age of the wine

License

This project is licensed under the MIT License. See the LICENSE.