# bluedb

> A lightweight json db with TypeScript support.

Latest version **1.0.0** (published 2020-02-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-02-23 |
| First published | 2020-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | r2fm |
| Maintainers | r2fm |
| Keywords | json, db, typescript, synchronous |

## Links

- npm: https://www.npmjs.com/package/bluedb
- npm.io page: https://npm.io/package/bluedb

## 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.0.0 (latest) — 2020-02-23

## README

# Introduction
*bluedb* is a lightweight json db with [TypeScript](https://www.typescriptlang.org/) support.


## Usage

```js
import { Connection } from "bluedb";

type DatabaseSchema = {
    array: string[],
    object: {
        nestedObject: {
            string: string,
        },
    },
    value: string | number,
};

const connection = new Connection<DatabaseSchema>("db.json");

connection.db.value = "Hello.";
connection.db.array.push("A value.");

connection.persistChanges();
```
Changes will be persisted **synchronously**.

By design, there aren't any predefined functions (e.g. for creating a collection). This is to allow for more flexibility when implementing this library in your own code. 
For example, you could extend it by wrapping it within a singleton-like, globally available container class.

```js
import { Connection } from "bluedb";

type DatabaseSchema = {
    array: string[],
    value: string | number,
};

export class DatabaseService {

    private static connection?: Connection<DatabaseSchema>;

    static createConnection(path: string) {
        DatabaseService.connection  = new Connection<DatabaseSchema>(path);
    }

    static getConnection() {
        if (!DatabaseService.connection) throw new Error ("No existing connection.");

        return DatabaseService.connection;
    }
}
```
```js
import { DatabaseService } from "../path/DatabaseService"

const connection = DatabaseService.getConnection();

connection.db.value = "Hello.";
connection.persistChanges();
```

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