Skip to content

Drarig29/ts-json-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Demo

npm Downloads

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.

About

A Node.js database using JSON file as storage. The result of requests are typed!

Resources

License

Stars

Watchers

Forks

Packages

No packages published