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

declarative-db

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

declarative-db

An easy-to-use declarative json-based database for Node

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

declarative-db

NpmVersion npm NodeVersion GitHub GitHub stars GitHub issues GitHub closed issues

An easy-to-use declarative json-based database for Node

Installation

npm install declarative-db

Usage

const path = require('path');
const declare = require('declarative-db');

// Declare json-based database
declare({
  filename: path.join(__dirname, './db.json'),
}).then(db => {
  // Use it as you would normally use an object (or array)
  db.users = [{
    username: 'loarca',
  }];

  // It will automatically save to disk asynchronously when appropriate
});

Since it's Promise based you can also use async-await

const path = require('path');
const declare = require('declarative-db');

(async () => {
  // Declare json-based database
  let db = await declare({
    filename: path.join(__dirname, './db.json'),
  });

  // Use it as you would normally use an object (or array)
  db.users = [{
    username: 'loarca',
  }];

  // It will automatically save to disk asynchronously when appropriate
})();

You should declare() only once per file and share declared objects/arrays across all modules, as every declared object/array is... exactly that... an object/array in memory that automatically saves to disk when appropriate

Options

{
  filename: path.join(__dirname, './db.json'),
  initialState: {},
  compression: 0,
}

filename

File to store data

initialState (default = {})

When no database file exists initialState is used, it may be an object or array

compression (default = 0)

Compression level ranging from 0 to 9

Level 0 outputs database to readable json

{
  "users": [
    {
      "username": "loarca"
    }
  ]
}

Levels from 1 to 9 match DEFLATE compression levels

To do

  • Documentation
  • Extensive testing
  • Smart scheduled saving
  • Protect scheduled saving from unexpected process termination
  • When filename option is not present, manage database in memory
  • Force saving when desired

Keywords

json

FAQs

Package last updated on 27 Nov 2019

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