Now that you have the database installed, lets connect and start using it.
import { Database, BaseModel } from"tydb";classMyModelextendsBaseModel { name:string="alex"; yearBorn:number=1992;}constmydb=newDatabase<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*/awaitmydb.insert([ MyModel.new({}) ]);/** or ...*/awaitmydb.insert([ MyModel.new({ name:"john" }) ]);awaitmydb.insert([ MyModel.new({ name:"john", }),MyModel.new({ _id:Math.random().toString(), name:"dina", yearBorn:27 })]);awaitmydb.delete({ filter: { name:"john" } });
The above example creates an in-memory-only database, so the data will not persisted and will be lost once the application is close or the instance is lost.
The following chart puts other ways to connect to a database into perspective: