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

node-chunkdb

v1.0.2

Published

json database for storing big data

Downloads

4

Readme

ChunkDB

Is a powerful json database for storing a large amount of data on a file system.

Require Node JS.

Installation


Using npm:

$ npm i node-chunkdb

In Node:

// Load build

import ChunkDB from 'node-chunkdb'

or

const ChunkDB = require('node-chunkdb');

Api:

// Initialization

let INDEX_FILE_PATH = '.../db/index.json';

let STORE_ENTITIES_PATH = '.../db/entities';

let db = new ChunkDB(INDEX_FILE_PATH, STORE_ENTITIES_PATH);

Options:

  • Enabling indentation when the entity is serialized in json format

    db.enableIndent = false (default)

    Note : it will cause an increase in the size of the entity file

  • Indentation value that will be used when the entity is serialized in json format

    db.indentSpaces = 2 (default) - Used only if indentation is enabled

EntityInfo Class:

This class is used to create the response object when creating a entity and contains the following properties:

  • id : unique id for entity create, example XEhsdaGxW

  • date: entity creation date

  • fileName: entities path

  • reference: optional information for searching the entity in the db, example { email: [email protected] }

  • Example

    let entityInfo = db.add(....);

    Output:

    entityInfo = {
        
      id: 'XEhsdaGxW',
      date: dayjs-object,
      filename: "server/db/entities/entity-XEhsdaGxW.json",
      reference: { email: [email protected] }
      
      }

Members:

- db.index.entities

Get the index of entities stored in the db

The collection contains the data necessary to find the requested entity,

entities is an array and therefore various methods can be used .find, .map, .sort, .some, .every etc .. to query

entities does not contain entity data but only EntityInfo

let entities = db.index.entities;

entities = [
  {
    id: 'XEhsdaGxW',
    date: '2020-05-19T06:32:35.173Z',
    fileName: 'server/db/entities/entity-XEhsdaGxW.json',
    reference: { options: { a: 1 } , creationTimeRequired: 1024 }
  },
  {
    id: 'Ywit-ZM94',
    date: '2020-05-22T08:10:33.842Z',
    fileName: 'server/db/entities/entity-Ywit-ZM94.json',
    reference: { options: { a: 2 }, creationTimeRequired: 500}
  }
]
Example Query:
let entities = db.index.entities.find((entity) => entity.reference.creationTimeRequired < 1000);

// OUTPUT
entities = [
  {
    id: 'Ywit-ZM94',
    date: '2020-05-22T08:10:33.842Z',
    fileName: 'server/db/entities/entity-Ywit-ZM94.json',
    reference: { options: { a: 2 }, creationTimeRequired: 500}
  }
]

let entityContent = db.get(entities[0].id);

// OUTPUT
entityContent = { name: Tony, role: admin }

Methods:

- db.add

Add to db (entity creation)

db.add(entity: object, reference: any) -> EntityInfo

// If an error occurs, an exception EntityError or otner will be raised

Entity: is a js object that will be serialized and adding to db.

Reference (optional): is anything that will serve in finding the entity

RETURN: the method returns an EntityInfo object with information about the created entity

  • Example

    let entityInfo = db.add({ name: Tony, role: admin }, { email: [email protected] });

- db.remove

Remove entity from the db

db.remove(id) -> boolean

Id: is the identifier of the entity

RETURN : the method returns a Boolean value to confirm the successful operation

  • Example

    let { id } = db.add(....);
    // id = 'XEhsdaGxW'
    db.remove(id); 
    // Output TRUE or FALSE

- db.get

Get entity content from the db

db.get(id) -> EntityContent || null

Id: is the identifier of the entity

RETURN : the method returns the contents of the entity

  • Example

    // id = 'XEhsdaGxW'
    let entityContent = db.get(id);
      
    // OUTPUT
    entityContent = { name: Tony, role: admin }