NeDB +打字稿

我如何使用types脚本类语法获得与NeDB的数据存储?

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() { ... } } } 

我应该在哪里创build和实例化我的数据存储?

我自己旋转我的轮子一段时间,我能够得到的数据库生成以下内容:

 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); } 

笔记:

  • 我确实为NeDB安装了@typings,请参阅NeDBtypes
  • 如果你看看上面的链接,他们提供他们用来validationtypes的testing。