New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ggdb

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ggdb

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

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

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()));

Keywords

json

FAQs

Package last updated on 24 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts