Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Drarig29/ts-json-db
A Node.js database using JSON file as storage. The result of requests are typed!
https://github.com/Drarig29/ts-json-db
Last synced: 3 months ago
JSON representation
A Node.js database using JSON file as storage. The result of requests are typed!
- Host: GitHub
- URL: https://github.com/Drarig29/ts-json-db
- Owner: Drarig29
- License: mit
- Created: 2020-03-27T19:01:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T09:53:37.000Z (over 2 years ago)
- Last Synced: 2024-06-23T11:22:46.098Z (5 months ago)
- Language: TypeScript
- Size: 170 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-json-db
A Node.js database using JSON file as storage. The result of requests are **typed**!
It's a wrapper around [node-json-db](https://github.com/Belphemur/node-json-db) which does the main job about the "database". This package is inspired by [RESTyped](https://github.com/rawrmaan/restyped) and its autocomplete and type checks.
![Demo](https://i.imgur.com/q3uLHJW.gif)
[![npm](https://img.shields.io/npm/v/ts-json-db.svg)](https://www.npmjs.com/package/ts-json-db)
[![Downloads](https://img.shields.io/npm/dt/ts-json-db.svg)](https://www.npmjs.com/package/ts-json-db)## Installation
Add `ts-json-db` to your existing Node.js project.
```bash
npm install ts-json-db
```## Usage
```typescript
import TypedJsonDB, { ContentBase, Dictionary } from "ts-json-db";interface Restaurant {
name: string
chef: string,
memberCount: number,
turnOver: number
}interface Login {
username: string,
password: string
};interface ContentDef extends ContentBase {
paths: {
'/login': {
entryType: "single",
valueType: Login
},
'/restaurants': {
entryType: "array",
valueType: Restaurant
},
'/teams': {
entryType: "dictionary",
valueType: string
}
}
}let db = new TypedJsonDB("config.json");
let result = db.get("/login");console.log(result);
```You can see in the `example` folder to find usage examples.