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

xdatabase

v1.1.6

Published

Database for nodeJS

Downloads

3

Readme

XDB

X Database, nodeJS Database

Documentation

General

Database Setup

The database is a maluable object. It is located where defined by the setDB() function. Please use the setDB function before using any of the database's functions, exception will cause errors.

Database Structure

The database structure is as follows:

  • database name (defined with setDB)
    • template name
      • id.json (id of object of template) (contains object data)
      • id.json...
      • base.json (base data of template)
    • template name...
      • id.json (id of object of template) (contains object data)
      • id.json...
      • base.json (base data of template)

IDs

All IDs in XDB start at 0 in accordance to almost all languages. The ids increment by 1 every new object/template.

Object Data

All data stored in objects is stored under object.data, all returned objects by xdb functions will require .data 'ing to get their preset data. This is due to the requirement of important system data baeing stored seperatly under: _type, _id, etc....

Errors/Bugs

Please report any on this repository.

Setups

setDB ( dbLocation )

Default Argument: "./db"

Example: xdb.setDB("./mydb")

Return Value: none

Sets default database location. Required to use database, exception of function will case errors. Place this function after the require, or before any other database functions.

resetDB ( )

Return Value: true/false (success/failure)

Example: xdb.resetDB()

Resets and removes database, destroying directory. Use function with precaution and only as a fail safe. Operation is not reverseable and cannot be undone or recovered.

Templates

addTemplate ( name )

Return Value: none

Creates a template under (name). Does not delete existing template, however it may update the id. Generally speaking creating the same template twice is not a issue.

getTemplate ( name )

Return Value: false/template (failure/found)

Attempts to return object that is defined. If the object doesn't exist, it will return false.

getAllTemplates ( )

Return Value: array

Attempts to return all existing templates. If none it will return an empty array.

deleteTemplate ( name )

Return Value: true/false (success/failure)

Attempts to delete specified template (name). If the template doesn't exist it will return false.

Objects

addObject ( type, data )

Return Value: object/false (success/failure)

Example: xdb.addObject("car", {name: "jimmy", brand: "mercedes"})

Adds an object with the specified type and with the specified data.

getOBject ( type, data )

Return Value: object/false (found/failure)

Example: xdb.getObject("car", {brand: "porche", age: 3})

Checks through template and attempts to match data argument with existing objects.

Input | Actual Data | Output --- | --- | --- {name: "bob} | {name: "bob"} | true (returns object) {age: 3} | {name: "bob", age: 3} | true (returns object) {name: "jimmy"} | {name: "bob", age: 3} | false (returns false)

The function will search through each object of the template until it finds a match and if not returns false.

getObjects ( type, data )

Return Value: Array

Example: xdb.getObjects("car", {brand: "porche", age: 3})

Checks through template and attempts to match data argument with existing objects, returns all that match.

Input | Actual Data | Output --- | --- | --- {name: "bob} | {name: "bob"} | true (returns object) {age: 3} | {name: "bob", age: 3} | true (returns object) {name: "jimmy"} | {name: "bob", age: 3} | false (returns false)

The function will search through each object of the template until it finds all matches, and if not it returns an empty array.

getObjectByID ( type, id )

Return Value: object/false (found/failure)

Exmaple: xdb.getObjectByID("car", 0)

Return searched object or returns false on failure.

getAllObjects ( type )

Return Value: Array

Example: xdb.getAllObjects("car")

Returns all objects under template that is defined (type).

deleteObject ( type, data )

Return Value: true/false (success/failure)

Returns true or false dependent on whether the deletion was succsessful. The delete function will search for a matching item in the database, however the object still remains and can be called upon by its id. However its data will only contain {deleted: true}.

Input | Actual Data | Output --- | --- | --- {name: "bob} | {name: "bob"} | true (deletes object) {age: 3} | {name: "bob", age: 3} | true (deletes object) {name: "jimmy"} | {name: "bob", age: 3} | false (goes to next object)

deleteObjects ( type, data )

Return Value: true/false (success/failure)

Returns true or false dependent on whether the deletion was succsessful. The delete function will remove all the items that match the specifed conditions, however the object still remains and can be called upon by its id. However its data will only contain {deleted: true}.

Input | Actual Data | Output --- | --- | --- {name: "bob} | {name: "bob"} | true (deletes object) {age: 3} | {name: "bob", age: 3} | true (deletes object) {name: "jimmy"} | {name: "bob", age: 3} | false (goes to next object)

deleteObjectByID ( type, id )

Return Value: true/false (success/failure)

If an object is found with the specified ID it will be deleted. However the object still remains and can be called upon by its id. However its data will only contain {deleted: true}.

deleteAllObjects ( type )

Return Value: true/false (success/failure)

Deletes all objects of the specified template (type). However the objects still remain and can be called upon by their ids. However their data will only contain {deleted: true}.