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

ggdb

v0.0.1

Published

Simple but powerful JSON database with index and sequences capabilities, recommended for up to 1 million of registers per file/collection.

Downloads

4

Readme

npm package

NPM version NPM License Downloads ISSUES

Support me for future versions:

BMC

PAGSEGURO

Simple but powerful JSON database with index and sequences capabilities, recommended for up to 1 million of registers per file/collection.

Warning: do not support multiple threads/processes or multiple access to same file, open the file and keep it open, when idle close the file
    
    

How install:

npm install ggdb

Basics

const { File } = require('ggdb');
const db = {
    user: new File('user.db'),
    address: new File('address.db')
}
 //sync have more performance but block event loop operations, great for single file dump or a database process only service
db.users.IOMode = "async"; //async or sync options

//await open all
await Promise.all(Object.values(db).map((file) => file.open()));

//you can check with .sequences or .indexes if some sequence/index exists
if(!db.users.sequences.some((sequence)=> sequence.property === 'id')){
    await db.users.createSequence("id", { start: 1, increment: 1 }); //use sequencial number
    await db.users.createIndex(100000, "id"); //create index with 100k bucket size
    await db.users.createSequence("created_at", { type: 'Date' }); //use current date ( Date.now() )
    // await db.users.createSequence("uuid", { type: 'UUID' }); //Generated unique identifier (UUID or Guid)
}

const user = {
    id: 0, //will be ignored because a sequences will override these value
    name: 'Ciro',
    surname: 'Spaciari'
}
//insert user in users.db file
user = await db.users.add(user);
//insert address and pass user.id
await db.address.add({
    address: 'Av. Whatever',
    number: 1234,
    state: 'SP',
    city: 'São Paulo',
    country: 'BR'
    user_id: user.id
});


//update by index
await db.address.updateByIndex({ id: address.id }, { number: 1164 });  //key, updated data, filter (optional), limit (optional), skip (optional), sort (optional) 

//update using table scan
await db.address.update((address)=> address.id > 10, { number: 1164 }); //key, updated data, filter (optional), limit (optional), skip (optional), sort (optional) 

//update using index + table scan
await db.address.updateByIndex({ user_id: user.id }, { number: 1164 }, (address)=> address.id > 10); //key, updated data, filter (optional), limit (optional), skip (optional), sort (optional) 

//filter using index
const addresses = await db.address.filterByIndex({ user_id: user.id }, (address)=> address.country === 'BR', 10, 0, { created_at: -1 }) //key, filter (optional), limit (optional), skip (optional), sort (optional) 

await db.users.filter((user)=> user.name === 'Ciro', 1); // filter, limit (optional), skip (optional), sort (optional) 

//deleteByIndex
await db.address.deleteByIndex({ id: addresses[i].id }); //key, filter (optional), limit (optional), skip (optional), sort (optional) 

//delete
await db.address.deleteByIndex({ id: addresses[i].id }); //filter, limit (optional), skip (optional), sort (optional) 
await db.users.delete((user)=> user.surname === 'Spaciari'); //filter, limit (optional), skip (optional), sort (optional) 

//also available:
//db.users.count (same parameters as filter , returns number)
//db.users.countByIndex  (same parameters as filterByIndex, returns number)
//db.users.exists (same parameters as filter, returns boolean)
//db.users.existsByIndex (same parameters as filterByIndex, returns boolean)

//await close all
await Promise.all(Object.values(db).map((file) => file.close()));