# light-db-json

> A lightweight and simple database which stores data in json file

Latest version **1.2.0** (published 2022-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install light-db-json
pnpm add light-db-json
yarn add light-db-json
bun add light-db-json
```

## 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 | 1.2.0 |
| Published | 2022-07-14 |
| First published | 2022-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ritesh Kumar |
| Maintainers | ritcode |
| Keywords | db, json, nodejs, small-scale-db |

## Links

- npm: https://www.npmjs.com/package/light-db-json
- Repository: https://github.com/ritcode/light-db
- Homepage: https://github.com/ritcode/light-db-json#readme
- Issues: https://github.com/ritcode/light-db-json/issues
- npm.io page: https://npm.io/package/light-db-json

## 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

- 1.2.0 (latest) — 2022-07-14
- 1.1.0 — 2022-07-13
- 1.0.0 — 2022-07-13

## README

# light-db-json

A lightweight database for small scale projects, simple to use and deploy, uses json file to store data.

Installation
------------

```sh-session
npm i light-db-json
```

Description
-------------
The package includes two types of storage, Database which stores data as key - value/object pair as well as wrapper to create Collections which stores data as array of documents.

Example Usage
-------------

### Database

```js
const { Database } = require('light-db-json');
const db = new Database();

db.set('activeUsers', 1000);
db.set('admin.username', 'ritcode');
db.set('admin.firstName', 'Ritesh')

db.has('admin'); // true
db.has('admin.username'); // true
db.has('admin.firstName'); // true
db.has('admin.age'); // false

db.remove('admin.firstName');
db.has('admin.firstName'); // false

db.get('admin.username'); // 'ritcode'
db.get('deveoper.name'); // undefined



db.toJSON(); // { activeUsers: 1000, admin: { username: 'ritcode' } }
```

### Collections

```js
const { Database } = require('light-db-json');
const db = new Database();

const Developers = db.createCollection('developers');

Developers.insert({ name: 'Ritesh', location: "India" });
Developers.insert({ name: 'Charles', age: 25, location:"Australia" });
Developers.insert({name: "Sia", location:"Poland", skills:["Nodejs", "react.js", "UI/UX"]});

Developers.update(
  d => d.age = 20,                    // what to update
  target => target.name === 'Sia'     // which documents to update
);

Developers.get(d => d.name === 'Ritesh'); // { name: 'Ritesh', location: "India" }
Developers.get(d => d.age > 18); // [{ name: 'Charles', age: 25, location:"Australia" }, { name: 'Sia', location:"Poland", skills:["Nodejs", "react.js", "UI/UX"] , age: 20 }]

Developers.delete( d => d.name == "Charles" ) // use with caution as it will delete all if no filter specified

```

Contribution
-------------

- You can open an issue or
- Create a valid pull request or
- Connect with me to have a discussion

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