ts-json-db
v2.0.5
Published
A Node.js database using JSON file as storage. The result of requests are typed!
Downloads
36
Maintainers
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 which does the main job about the "database". This package is inspired by RESTyped and its autocomplete and type checks.
Installation
Add ts-json-db
to your existing Node.js project.
npm install ts-json-db
Usage
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<ContentDef>("config.json");
let result = db.get("/login");
console.log(result);
You can see in the example
folder to find usage examples.