# toiletdb

> flush your json to a file

Latest version **2.0.0** (published 2019-04-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install toiletdb
pnpm add toiletdb
yarn add toiletdb
bun add toiletdb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-04-04 |
| First published | 2017-02-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 220 |
| Author | max ogden |
| Maintainers | jhand, maxogden, yoshuawuyts |

## Links

- npm: https://www.npmjs.com/package/toiletdb
- Repository: https://github.com/maxogden/toiletdb
- Homepage: https://github.com/maxogden/toiletdb#readme
- Issues: https://github.com/maxogden/toiletdb/issues
- npm.io page: https://npm.io/package/toiletdb

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [last-one-wins](https://npm.io/package/last-one-wins.md) ^1.0.4

## Recent versions

- 2.0.0 (latest) — 2019-04-04
- 1.4.1 — 2018-01-22
- 1.4.0 — 2017-05-19
- 1.3.0 — 2017-05-17
- 1.2.1 — 2017-02-02
- 1.2.0 — 2017-02-02
- 1.1.1 — 2017-02-02
- 1.1.0 — 2017-02-02
- 1.0.0 — 2017-02-02

## README

# 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')`](//www.npmjs.com/package/last-one-wins) to ensure atomicity of CRUD actions

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

## API

```js
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

```js

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

// write/read as normal
```

---
_Source: https://npm.io/package/toiletdb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
