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

bigdb

v2.0.5

Published

A json file database

Downloads

17

Readme

Bigdb.

Bigdb is a javascript backend library for reading and writing data in a json file database. It store it's data locally on the server just like sqlite, but instead it store its data in a json file. Bigdb can read and write up to 10gb data. It can be used with any library that have access to fs module of node js.

Installation.

Install with npm i bigdb.

Usage.

Bigdb METHODS are similar to that of mongoose (mongodb) and can perform both read and write operation.

conts {Bigdb} = require('bigdb')
//OR
import {Bigdb} from 'bigdb'

To create new document, for example Post, call the method Bigdb()

  • Your first parameter is the path where you database will leave, can be null as well

  • Second paramter is the name of the collection and

  • Optionally you can pass true or false (boolean) to the third parameter of the function.This spacifies wheather you want to keep your collection in one file or ecach file for each collection.

    true - each file for each collection.

    false - one file called database.json.

Call Bigdb and pass nessecary parameter.

const Posts = Bigdb(null, 'Posts') 
//will create Db/database.json at the root of your app

//OR

const Post =  Bigdb('Database', 'Posts') 
//will create Database/database.json at the root of your app

//OR

const Post =  Bigdb(null, 'Posts', true)
//will create Db/Posts.json at the root of your app

//OR

const Post = Bigdb('/Database/folder', 'Posts') 
//will create /Database/folder/Post.json at the root of you app


let result = await Post.create({title:'Post title 1',body:'i am Post 1'}) //single
let result = await Post.create([{title:'Post title 1',body:'i am Post 1'}, <...>]) //bulk
//this creates new documens in the database

The above code will create a corresponding path at the root of your app if it does not exist, - "Posts" is the name of the collection, if we had passed users it would create a users collection in the database

Then it will return something like this;

{
  id: 1,
  title:'Post title 1',
  body:'i am Post 1',
  createdAt: '2024-01-08T09:39:09.976Z',
  updatedAt: '2024-01-08T09:39:09.976Z'
}

Its that simple

It auto asign createdAt, updatedAt and id to it as it saves to database. The id is an autoincreamenting id.

As i told you earlier that the methods are similar to mongodb methods, All queries are case insensitive, uppercase letter are the same as lowercase letter ('dog' === 'doG' === 'DOG').

We also have many more methods like;

.findById(id)
await Post.findById(1)

It returns the document with id 1 from Posts collection.

.findOne()
await Post.findOne({name:{$has:'john'}})

It returns the first document that matches the query

.find()

This takes in two optonal parameter,

  • First paramerter is the query
  • Second parameter is attribute you don't want to appear in the result Every query that has .find() ends with .get() .eg
await Post.find().get()
await Post.find({name:'jane doe', age:20}).get()
await Users.find({name:'jane doe', age:20}, {password:false, salary:false}).get()

It returns an array of all the documents that matches the query from the collection.

[
    {
        id: 1,
        title:'Post title1',
        body:'i am Post 1',
        createdAt: '2024-01-08T09:39:09.976Z',
        updatedAt: '2024-01-08T09:39:09.976Z'
    },
    {
        id: 2,
        title:'Post title2',
        body:'i am Post 2',
        createdAt: '2024-01-08T09:39:09.976Z',
        updatedAt: '2024-01-08T09:39:09.976Z'
    },
]

Also you can request for particular kind of data like

await Post.find({views:2}).get()
await Post.find({views:2, title:{$has:'Post'}}).get()

We also have the .sort(), .skip() and .limit()

await Post.find({}).sort({id:1}).get() 
//1 for ascending  and -1 for for descending
await Post.find().skip(2).get() 
//skips the first two match

await Post.find().limit(5).get() 
//it retuns 5 documents

await Post.find().sort({id:-1}).limit(5).skip(2).get() 
/*it retuns 5 documents sorted in 
descending order basing on id 
*/

The .sort(), .limit() and .skip() have no orders in which they are called like in mongodb.

sort() - For sorting the result in either ascending or descending order. It takes in only one object parameter
limit() - For limiting the number of records you want back. It takes in only one inter parameter(Number of record you want back).
skip() - For akipping some the number of records. It takes in only one inter parameter(Number of record you want skip).
await Post.find().sort({id:-1, user_name:1}).limit(5).skip(10).get() 
await Post.find().limit(5).sort({id:-1}).get() 
await Post.find().limit(5).skip(3).get() 
//the result for the above are the same
.update()
await Post.update(2, {title:'updated title'})
/*update the title of document with id 2 
to 'updated title' and returns the updated document
*/
.findOneAndUpdate()
await Post.findOneAndUpdate({views:10}, {title:'updated title'})
/*update the title of the first match
 to 'updated title'.
*/
.findAndUpdate()
await Post.findAndUpdate({views:10}, {title:'updated title'})
/*update the title of all the matches to 'updated title'
*/

Update has criteria like; $inc

await Post.update(3, {$inc:{views:1}})
//
await Post.findAndUpdate({views:2}, {$inc:{views:5}})
/* inceasing views  by spacified value
*/

$mul

await Post.update(3, {$mul:{views:1}})
//
await Post.findAndUpdate({views:2}, {$mul:{views:5}})
/* multiplies views by spacified value.
*/

$push

await Product.update(3, {$push:{price:100, <...>}})
//
await Post.findAndUpdate({id:{$gte:10}}, {$push:{views:5, <...>}})
/* adding new value to an array attribute the matches 
spacified criteria
*/

$pull

await Product.update(3, {$pull:{price:100}})
//
/* remove the first occurence of 100 frrom price array
*/

$pullAll

await Product.update(3, {$pullAll:{price:100}})
//
await Post.findAndUpdate({id:{$gte:10}}, {$pullAll:{price:[100, 250]}})
/* remove all the prices sprcified from the price array for
elements that spacified criteria
*/
.delete()
await Post.delete(2)
// deletes document with id 2

await Post.delete([2, 4, 5])
// deletes document with ids of 2 ,4 ,5
.findOneAndDelete()
await Post.findOneAndDelete({title:{$has:'updated'}})
/*
deletes first match of the query
*/
.findAndDelete()
await Post.findAndDelete({title:{$has:'updated'}})
/*
deletes all the matches of the query
*/
.last()
await Post.last() 
//
await Post.last({title:{$search:'updated'}})
/*
both returns the last match of the query
*/
.countDocuments()
await Post.countDocuments() //1000
//
await Post.countDocuments({title:{$search:'updated'}}) //25
/*
counts the number of documents that matches the query
*/
.paginate()

This takes in two optonal parameter,

  • First paramerter is the query.
  • Second parameter is attribute you don't want to appear in the result.

This method has .get() at the end. This returns the data together with some metedata, call the get at the end page() - The page you want the data for. It takes in an interger(page you want the data for). perPage() - The perPage for passing the number records you want page. It takes in an interger(the number records you want perPage).

await Post.paginate().get()
await Post.paginate({}).get()
//defaults to page 1 and perPage of 12

await Post.paginate().page(2).get() 
//returns page 2 and perPage of 12

await Post.paginate().page(2).perPage(5).get()
//returns page 2 and perPage of 5 

await Post.paginate({age:10}, {title:false}).page(2).perPage(5).get()
//returns page 2 and perPage of 5 

The result look like this.

{
  num_records:17,
  page: 1,
  par_page: 12,
  has_next: true,
  has_prev: false,
  next_page: 2,
  prev_page: null,
  num_pages: 2,
  result: [
    {
      Post: "Post1",
      id: 1,
      createdAt: "2024-01-08T10:26:27.158Z",
      updatedAt: "2024-01-08T10:26:27.158Z"
    },
    {
      Post: "Post2",
      id: 2,
      createdAt: "2024-01-08T10:26:28.629Z",
      updatedAt: "2024-01-08T10:26:28.629Z"
    }
  ] 
}

Some of the different ways of filtering or querying for specific kind of data are;

$lt

await people.find({age:{$lt:18}}).get()
//returns people whose age is less than 18

$lte

await people.find({age:{$lte:18}}).get()
//returns people whose age is less than or equal to 18

$gt

await people.find({age:{$gt:18}}).get()
//returns people whose age is greater than to 18

$gte

await people.find({age:{$gte:18}}).get()
//returns people whose age is greater than or equal to 18

$eq

await pawait eople.find({age:{$eq:18}}).get()
//returns people whose age is equal to 18

$neq

await people.find({age:{$neq:18}}).get()
//returns people whose age is not equal to 18

$bt

await people.find({age:{$bt:[5,10]}}).get()
//returns people whose age is between 5 and 10

$nbt

await people.find({age:{$nbt:[5, 10]}}).get()
//returns people whose age is not between 5 and 10

$has

await people.find({country:{$has:'ug'}}).get()
//people whose country has ug in their name

$hasNo

await people.find({country:{$hasNo:'ug'}}).get()
//people whose country has no ug in their name

$sw

await food.find({name:{$sw:'ap'}}).get()
//foods whose name starts with ap 

$ew

await food.find({name:{$ew:'ilk'}}).get()
//foods whose name end with ilk

$nsw

await food.find({name:{$nsw:'ap'}}).get()
//foods whose name is not starting with ap 

$new

await food.find({name:{$ew:'ilk'}}).get()
//foods whose name is not ending with ilk

$in

await food.find({prices:{$in:5}}).get()
//for array fields
//foods whose prices list has 5

$nin

await food.find({prices:{$nin:5}}).get()
//for array fields
//foods whose prices list has no 5

$all

await food.find({prices:{$all:[5, 10]}}).get()
//for array fields
//foods whose prices matches all the value supplied as array 

$or

await user.find({$or:{firstname:'tom', lastname:{$has:'jo'}}}).get()
//users whose firstname is tom or lastname has jo in it

await food.find({$or:{name:'pizze', price:{$lt:20}}}).get()
//foods whose name is pizza or price is less than 20

$and

await user.find({$and:{firstname:'tom', lastname:{$has:'jo'}}}).get()
//users whose firstname is tom and lastname has jo in it

await food.find({$or:{name:'pizze', price:{$lt:20}}}).get()
//foods whose name is pizza and price is less than 20

You can have queries like;

await user.find({
    country:'canada',
    first_name:{$has:'ni'},
    last_name:{$has:'jo'},
    age:{$gte:20},
}).get();
//returns array
NB:

-Both .paginate() and .find() methods require you to call a get method at the end to return the data.

Both .paginate() and .find() takes in second optional parameter which spacifies which attribute you want back or not, all attributes will be return by default

await user.find({},{password:true, create_at:false})
await user.find({country:'USA'},{password:false, name:false})
//returns results without password attribute

THANKS, from Bigdb team