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

usnpdb

v1.0.11

Published

Ultrasimple, not for production, just for testing and fun JSON based database - in fact, just to avoid using files. NOT FOR PRODUCTION

Downloads

20

Readme

UltraSimple Not for Production DataBase (usnpdb)

Okay, this is just a test module, and we use it for some simple projects since we are too lazy to write file handler functions. If you like it and want to use it, it's up to you :) If you find it useful and want to extend it, please join us; we will be happy to have someone who actually does some work.

What it is?

This is a simple interface to JSON text files that we use as a simple database for configurations and some simple data. Mainly, we use it in the development phase, but have found a place for it even in some production solutions.

Installation

This is simple package, just use standard npm install : npm install -s usnpdb

Usage

Inicialization

To use usnpdb you need to initialise it by giving a path where your JSON files will be stored. For example:

const iotDB = require('usnpdb');
iotDB.initRepository('./data');

Initially, the database is initialized with a 4-character identation, and if you want files to take up less space, add a second parameter to the initialization, like in the example.

const iotDB = require('usnpdb');
iotDB.initRepository('./data', false);

Basic usage

For example, we have JSON object like this:

let myUser = {
    "name" : "John Doe",
    "age" : 25,
    "address" : {
        "street" : "Some street",
        "houseNo" : 15,
        "town" : "Gotham City",
        "postal" : 666666,
        "country" : "Mordor"
    },
    "active" : false
}

Here is few basic examples of usage.

Drop collection/table

iotDB.drop('users');

Count records

iotDB.count('users');

Insert record

iotDB.insert('users', myUser);

Insert data as new record. Before insert, add _uid as unique ID for object {string}.

Read all records

let users = iotDB.getAll('users');  

Return array of objects or empty array.

Update record

iotDB.update('users', myUser);

If the object doesn't exist, it behaves like an insert record.

Delete one record

iotDB.deleteOne('users', { age : 25 });

Delete first record that matches the specified conditions.

Delete records

iotDB.delete('users', { age : 25 });

Delete all records that matches the specified conditions.

Delete record by ID

iotDB.deleteByID('users', _uid);

Delete record with specified ID.

Find by ID

let user = iotDB.findByID('users', _uid);

Find one record

let user = iotDB.findOne('users', { age : 25 });

Find one by path

let user = iotDB.findOneByPath('users', { 'address.houseNo' : 25 });

Find all records by JSON path

Find like

let users = iotDB.findLike('users', { name : 'hn' });

Find that starts with

let users = iotDB.findStartsWith('users', { name : 'Joh' });

Find all

let users = iotDB.find('users', { age : 25 });

Utility functions

IoT date/time

Ok, this is funny story. So, we had some serious issues with date format management, and for the needs of IoT sensors and processing, we needed a simple and fast way to handle time. So, we tried this approach, and we liked it.
The principle is very simple, so we created a string from the date in the format 'ddMMyyyyhhmmss' and then converted it into a number. This way, we achieved fast searching and straightforward parsing when we need any part of the date. It also made it much easier for us to manipulate and check elapsed time and other aspects, primarily related to IoT sensors and monitoring. Furthermore, when we transmit this format to small IoT microcontrollers, we can easily manage it.
Similarly, when we convert this format into a string, finding data has proven to be much faster than using the Date object. An example is locating and compering a month within a date. It turns out that the substring function is much faster.
And, of course, since we're a bit peculiar, this seemed more logical and simpler to us than having to figure out how to use the JS Date() object every time and wrestle with its logic.
I understand, some might say that we could have achieved all of this with milliseconds, but... well, this way, it was just simpler for us.

For example, if we have January 12 2023 @ 10:05:33 it is converted to "20230112100533" and from that to number 20230112100533.

Full date/time to IoT dateTime

let iotDate = iotDB.toIoTDateTime(new Date());

Convert Date object to IoT date-time format

Date to IoT date

let iotDate = iotDB.toIoTDate(new Date());

Convert Date object to IoT date format

Date to IoT time

let iotDate = iotDB.toIoTTime(new Date());

Convert Date object to IoT time format

FAQ

Why almost no error handling has been implemented?

Alright, I know we should have implemented at least basic error handling, but honestly, we're too lazy to do that. On the other hand, since we wrote it, we know how to use it, so there you go... (yes, we're really that lazy). Also, like all good programmers, we're thrilled about writing documentation and error management, so...

Will you correct the errors if we report them?

Of course, we can't guarantee a specific timeframe for addressing errors if they occur. If it's about new features, we'll assess how much time it takes and how it fits into our plans before making a decision.

Can we join and help with the development?

Of course, we'd be happy if you want to join. We're just not sure how to include you, as this is the first package we've put on npm, so we don't know how it's done, but if you explain it to us... no problem.