# json-table-lite

> Simple JSON storage facility

Latest version **0.3.2** (published 2019-10-07) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install json-table-lite
pnpm add json-table-lite
yarn add json-table-lite
bun add json-table-lite
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2019-10-07 |
| First published | 2017-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 2 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jesse Tijnagel |
| Maintainers | guilala |
| Keywords | storage, table, db, sqlite, JSON |

## Links

- npm: https://www.npmjs.com/package/json-table-lite
- Repository: https://github.com/guilala/json-table-lite
- Homepage: http://guila.la
- Issues: https://github.com/guilala/json-table-lite/issues
- npm.io page: https://npm.io/package/json-table-lite

## Dependencies (2)

- [make-dir](https://npm.io/package/make-dir.md) ^3.0.0
- [sqlite-async](https://npm.io/package/sqlite-async.md) ^1.0.12

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.3.2 (latest) — 2019-10-07
- 0.3.0 — 2019-10-03
- 0.2.5 — 2019-09-23
- 0.2.4 — 2019-09-09
- 0.2.3 — 2019-09-09
- 0.2.2 — 2018-11-21
- 0.2.1 — 2018-10-25
- 0.2.0 — 2018-09-25
- 0.1.8 — 2018-08-17
- 0.1.7 — 2018-04-10
- 0.1.6 — 2018-01-25
- 0.1.5 — 2017-10-04
- 0.1.4 — 2017-10-04
- 0.1.3 — 2017-10-04
- 0.1.2 — 2017-10-04
- … 6 more at https://npm.io/package/json-table-lite/versions

## README

# json-table-lite
KISS JSON storage facility for Node.js

## History Repeating
Small to medium size projects are often in need of a fast, easy and lightweight, yet reliable way of storing data server side. But choosing the obvious often results into trouble.

## What kind of trouble?
* Storing plain JSON files
   * To slow
   * Not easy to use
   * Inefficient
   * To much data in memory
* SQL server
   * Sql syntax overhead
   * Not compatible with json data without extension
   * Overkill
   * To centralized, not portable
   * Counterproductive
* SQLite
   * Sql syntax overhead
   * Doesn't configure automatically
   * Counterproductive
* Mongodb
   * Eats to much cpu when idle
   * Overkill
   * To centralized, not portable
* Redis, LevelDB, nedb, nedb-core, etc
   * To much data in memory
* Realm
   * Not bad, wrong license

## Solution
A simple, one dimensional parser wrapper around sqlite3, for storing and retrieving JSON data.

## Probabilities
* SQLite and it's Node.js client are fast, lightweight and reliable.
* SQLite is portable.

## Why no features for handling multiple tables
* The idea behind this approach is storing a table of JSON data, and not so much storing single values in relational tables.
* You can still handle relations between tables with Javascript just as easy (easier).
* SQLite seems to block subsequent queries while it is writing. By using a separate file for each table, writing tables is non-blocking for others.
* No SQL statement syntax please, and Keep It Simple, Stupid.

## Wish
* ~~Count~~
* Basic operators
* Unit tests

## Example
Clone source code from Github and run the [example](test.mjs).
```bash
git clone git@github.com:guilala/json-table-lite.git
cd json-table-lite
npm i
npm run test
```

The output should be something like this.
```javascript
[ 'id', 'furniture' ]
[ 'id', 'age', 'surname', 'name' ]
[ 'id', 'age', 'surname', 'name', 'town' ]
[ { id: 1, age: 30, surname: 'Doe', name: 'Jane', town: null } ]
[ { id: 1, age: 31, surname: 'Doe', name: 'Jane', town: null },
  { id: 2, age: 36, surname: 'Doe', name: 'John', town: 'Brussels' } ]
2
[ { id: 1, age: 31, surname: 'Doe', name: 'Jane', town: null } ]
```

A getProperties will at least return 'id'. This is the unique identifier index column of SQLite.

The first output shows two properties because a first record with the property 'furniture' has been stored in a db with file name 'test2.db'. This action started last in test.mjs, and runs asynchronous in parallel with the first. It outputs first because the record that gets stored is smaller.
```javascript
[ 'id', 'furniture' ]
```

The second output shows four properties because a first record with 'name', 'surname' and 'age' has been stored in a db with file name 'test1.db'. You could also set a custom id as long as it's a unique integer.
```javascript
[ 'id', 'age', 'surname', 'name' ]
```

After a second record has been stored, containing a new property, you can see that it's automatically added. In SQLite this adds a new column.
```javascript
[ 'id', 'age', 'surname', 'name', 'town' ]
```

The next output is from retrieving Jane's record only.
```javascript
[ { id: 1, age: 30, surname: 'Doe', name: 'Jane', town: null } ]
```

Following output is from getting all records after Jane's age has been updated.
```javascript
[ { id: 1, age: 31, surname: 'Doe', name: 'Jane', town: null },
  { id: 2, age: 36, surname: 'Doe', name: 'John', town: 'Brussels' } ]
```

A count of records with surname 'Doe' results in two records.
```javascript
2
```

Last output shows all records after John's record has been deleted.
```javascript
[ { id: 1, age: 31, surname: 'Doe', name: 'Jane', town: null } ]
```

Look into [test.mjs](test.mjs) to see how this has been achieved.

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