Nodding Previously Managed

    ts-json-db
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.5 • Public • Published

    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.

    Install

    npm i ts-json-db

    DownloadsWeekly Downloads

    3

    Version

    2.0.5

    License

    MIT

    Unpacked Size

    30.8 kB

    Total Files

    7

    Last publish

    Collaborators

    • drarig29