Getting Started
Installation & basic usage
Installation
$ npm i tydb
$ yarn add tydbimport { Database, BaseModel } from "tydb";
class MyModel extends BaseModel {
name: string = "alex";
yearBorn: number = 1992;
}
const mydb = new Database<MyModel>({
// database configuration
// only the "ref" property is required
ref: "mydb",
model: MyModel
// ... etc
});
/*
* Inserting a document based on the default
* values specified by the class above
*/
await mydb.insert([ MyModel.new({}) ]);
/*
* or ...
*/
await mydb.insert([ MyModel.new({ name: "john" }) ]);
await mydb.insert([
MyModel.new({
name: "john",
}),
MyModel.new({
_id: Math.random().toString(),
name: "dina",
yearBorn: 27
})
]);
await mydb.delete({ filter: { name: "john" } });
Last updated