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

dataput

v1.2.1

Published

JSON Database with files

Downloads

4

Readme

Introduction

Dataput is an npm package that integrates a database service without the need for external apps such as MySQL, but using JSON files created in your project folder.

Why is it faster than other libraries?

This library is synchronous, so it doesn't use promises or callback functions.

How to install it

  • npm init for creating package.json
  • npm i dataput --save for installing the package

Step of use

Step 1 Import library

First, we need to import the package into our sketch. const Dataput = require('dataput');

Step 2 Set up databases

We also need to declare the databases we want to use, whether they exist or not So keep this code always in your sketch, even if it's the 1000th time you run it const databaseLogin = new Dataput('DATABASE_NAME');

The creation of the files is AUTOMATIC

Once the database has been declared, if it does not exist the library will automatically create a folder (by default called 'storage', but it can be changed by setting the directory as the second parameter of the database declaration in the constructor) where it will then put the necessary files, which it will automatically create . In this case, it will create the directory: ./storage with the file ./storage/DATABASE_NAME.min.json

Step 3 definition of the table headers

Each database is a table, you can create as many databases as you want, but it is important that for each of them the headers are set, that is the names of the columns (example: ID, Name, Surname). You can do it this way

databaseLogin.headers = ['ID', 'Name', 'Surname', 'Email address', 'Password'];

These headers can be changed when you want, and depending on the number of elements in the header, the content will adapt, so be careful because if we change the headers with a smaller number, some data in the content of the table will be deleted.

If we remove the "Surname" header from this table, the contents of the table will adapt to the number of Headers, so we will lose the given password

Auto Increment

Many databases, if not all of them need a column that is a primary key and therefore that has a unique value, and often using autoincrement which is not necessary, it is very important to have it, to do this just use this syntax after the declaration database: databaseLogin.autoIncrement = 'ID'

'ID' is the column that must have the property, and like the other options it can be changed later

Methods INSERT, DELETE, UPDATEROW, TRUNCATE, DROP, QUERY

Insert

Insert is used to insert a row into a database, and can be used simply like this:

As you can see, it is very easy to insert a line, just use an object in JSON format. The ID column as it has the autoincrement property can receive as content "Dataput.AI", which makes the library understand that it must insert the value automatically, if "Dataput.AI" is used on a column without this property, an error will be returned.

Delete

Insert is used to insert a row into a database, and can be used simply like this:

The delete method accepts as its only parameter a search that will be performed, and ** all ** rows that match the search will be deleted.

Updaterow

The updateRow method accepts two parameters, the first is the one to search for the rows to update, and the second is the object that contains the changes

In this case, all lines with the name "Simone" and email address "[email protected]" will have a change to the name and surname with "Andrea" and "Bergamaschi" respectively

Truncate

Truncate serves to eliminate ** all ** data from a datbase

No parameters required.

Drop

Truncate need to drop a database

No parameters required.

Query

The query method accepts two parameters and it's used for searching rows, the first argument is the one to search for rows, and the second is a boolean (default false, so it is not necessary to put it) which provides a more detailed output.

rowsNumber

Will return the number of rows inside of this database

Error handling

This library, not being asynchronous, returns any errors with functions, for example:

It will return: {result: false, error: "Auto Increment column is not the same as declared, you inserted: 'Nome', expected: 'ID'"}

So pay attention to: ".result" in return to the method used.

Secondary methods

Dataput.exists (not database.exists) it is a method to use to understand if a database exists or not, for example: Dataput.exists('test') => false Dataput.exists('DATABASE_NAME') => true