@acai/model 中文文档教程

发布于 3年前 浏览 25 项目主页 更新于 3年前

GitHub 构建状态”></a> <a href=Support

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

GitHub Build Status Support

Açaí's Framework model

Models are a easy way to group your data with methods to format it, save and other crud operations.

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
更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文