0.1.5 • Published 6 years ago

jabdb v0.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

npm.io

WORK IN PROGRESS

Just A Basic DataBase, a TypeScript-first simple json database for storing plain objects.

Installation

# using npm
npm install jabdb --save

# using yarn
yarn add jabdb

Usage - TypeScript

WORK IN PROGRESS

Importing

import JabDB from "jabdb";
import { SingleFileAdapter } from "jabdb";

Creating the database

const adapter = new SingleFileAdapter("data.json"); // Has to be a .json file
const db = new JabDB(adapter);

// Connect to the database
await db.connect();

Creating a new table

const users = await db.createTable("users");

Getting a table

const users = await db.getTable("users");

Creating entry in table

const id1 = await users.create({ name: "John Stone", age: 30 });
const id2 = await users.create({ name: "John Stone", age: 30 }, "johnstone");

// id1 -> "0" or next available id in table
// id2 -> "johnstone" if it is available else next available id

Getting object by its id

const user = await users.get("johnstone").value();

Finding entry

const foundUser = await users.findFirst(v => v.name == "John Stone").value();
const foundUsers = await users.findAll(v => v.age == 30).values();

Updating entry

There are multiple ways of updating an entry:

Put

The put method overrides the entry with the specified id.

await users.put("johnstone", { name: "John Stone", age: 31 });

Patch

The patch method updates the fields of the object specified. Patch is implemented using assignIn from Lodash.

await users.patch("johnstone", { age: 32 });

// 'johnstone' -> { name: "John Stone", age: 32 }

PatchWith

The patchWith method works like patch, but takes a customizer function. PatchWith is implemented using assignInWith from Lodash.

See the Lodash documentation for more info

Deleting entry

await users.delete("johnstone");
0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago