@acai/model 中文文档教程
Açaí's Framework model
模型是一种使用格式化、保存和其他 crud 操作的方法对数据进行分组的简单方法。
Usage
Declare model
import Model from "@acai/model";
@Model.Table("user", "connection2")
export class User extends Model {
@Model.Field()
public id: string;
@Model.Field()
public name: string;
@Model.Field()
public email: string;
@Model.Field()
public avatar?: string;
}
CRUD operations
// get
const user = await User.find("id");
const user2 = await User.query().where("name", "John").first();
// create/update
const user = new User();
await user.save();
// delete
const user = await User.find("id");
await user.delete();
Extending types
Types parts
- onCreate When setting a field value into the model
- onSave From model to database
- onRetrieve From database to model
- onSerialize From model to JS object
更多