Skip to content

Latest commit

 

History

History
80 lines (50 loc) · 2.09 KB

readme.md

File metadata and controls

80 lines (50 loc) · 2.09 KB

Jason

A simple typesafe JSON ORM library that allows you to interact with data stored in a JSON database. The library provides a simple ORM-like interface for working with data.

Installation

  • npm
npm install @probablyarth/jason
  • yarn
yarn add @probablyarth/jason

Usage

Here is an example of how to use the library

import { Init, Model } from "@probablyarth/jason";

Init("path/to/database.json");

interface IUser {
  name: string;
  age: number;
}

const userModel = new Model<IUser>("users");

const userId = userModel.insertOne({
  name: "probablyarth",
  age: 17,
});

const user = userModel.findById(userId);

console.log(user);

You can also use it without types,

import { Init, Model } from "@probablyarth/jason";

Init("path/to/database.json");

const userModel = new Model("users");

const userId = userModel.insertOne({
  name: "probablyarth",
  age: 17,
});

const user = userModel.findById(userId);

console.log(user);

More examples in the examples folder

Disclaimer

Json files should not be used as database for projects that store huge amounts of data. Although a json file of 1mb should be able to hold about 5-10k records (depends on the size of records). All the data is loaded in the memory temporarily but this shouldn't be any problem either when working with small projects or projects that require DB to be hosted locally.

Motivation

I was working on a side project which needed a database to be hosted locally by the user. It would be a very big hassle for the end user if he had to setup mongodb or mysql on his pc to use that project and the data won't be that much either so there was no point in setting up a traditional dbms. I wanted a lighter and simpler solution, that's when I thought about json files.

Buy Me A Coffee

TODO

  • Better Queries, perhaps a queryBuilder?
  • Docs? Maybe