Abel
Abel

Reputation: 355

NeDB + Typescript

How can I get a datastore with NeDB using typescrip classes syntax?

namespace NamespaceName {

"use strict";

export class Persistence {

    private attrs: Type;

    public static $inject: Array<string> = [];

    constructor(
    ) {
        this.attr1 = "";
    }

    // Public Methods
    public method1() {
        ...
    }

    // Private Methods
    private method1() {
        ...
    }
  }
}

Where should I create and instantiate my datastore?

Upvotes: 1

Views: 3465

Answers (1)

Tim
Tim

Reputation: 36

I was spinning my wheels on this myself for a while and I was able to do get the database to generate with the following:

import NeDB = require('nedb');
//test class
class duck{
    body: string;
    constructor(body: string)
    {
       this.body = body;
    }
}

//method from where I init my database.
testdb() {
    var db:any = new NeDB("./file.db");
    var obj:duck= new duck("A normal duck body");
    db.loadDatabase();
    db.insert(obj);
}

Notes:

  • I do have the @typings installed for NeDB see NeDB Typings
  • If you look at the above link they provide the tests they used to verify the typings.

Upvotes: 1

Related Questions