Socket
Book a DemoInstallSign in
Socket

toiletdb

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toiletdb

flush your json to a file

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
3
Created
Source

toiletdb :toilet:

flushes an object to a JSON file. lets you do simple CRUD with async safely with the backend being a flat JSON file

uses require('last-one-wins') to ensure atomicity of CRUD actions

note: if you write Buffers they will be converted to hex strings

API

var toilet = require('toiletdb')
// or require the in-memory version if you want
var db = require('toiletdb/inmemory')

// pass the name of the json file to use
var db = toilet('./data.json')

// open the db
await db.open()

// read data from data.json
var data = await db.read()
// read `key` inside data.json
var value = await db.read(key)

// sets `key` to `val` inside data.json
await db.write(key, val)

// deletes `key` key from data.json
await db.delete(key)

// deletes everything from data.json  
await db.flush()

// synchronous version
db.flushSync()

Custom FS


// pass the name and custom fs
var db = toilet({fs: customFs, name: './data.json'})

// write/read as normal

FAQs

Package last updated on 04 Apr 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