Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/probablyarth/jason
A simple typesafe JSON ORM library that allows you to interact with data stored in a JSON database
https://github.com/probablyarth/jason
javascript javascript-library json json-db json-orm orm orm-library typescript typescript-library
Last synced: about 1 month ago
JSON representation
A simple typesafe JSON ORM library that allows you to interact with data stored in a JSON database
- Host: GitHub
- URL: https://github.com/probablyarth/jason
- Owner: probablyArth
- Created: 2023-02-21T07:07:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-07T08:43:49.000Z (7 months ago)
- Last Synced: 2024-10-15T16:04:58.493Z (about 1 month ago)
- Topics: javascript, javascript-library, json, json-db, json-orm, orm, orm-library, typescript, typescript-library
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@probablyarth/jason
- Size: 86.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 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
```bash
npm install @probablyarth/jason
```- yarn
```bash
yarn add @probablyarth/jason
```## Usage
Here is an example of how to use the library
```typescript
import { Init, Model } from "@probablyarth/jason";Init("path/to/database.json");
interface IUser {
name: string;
age: number;
}const userModel = new Model("users");
const userId = userModel.insertOne({
name: "probablyarth",
age: 17,
});const user = userModel.findById(userId);
console.log(user);
```You can also use it without types,
```javascript
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](https://github.com/probablyArth/jason/blob/main/examples.ts)
## 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.
## TODO
- Better Queries, perhaps a queryBuilder?
- Docs? Maybe