@acai/model

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

Usage no npm install needed!

<script type="module">
  import acaiModel from 'https://cdn.skypack.dev/@acai/model';
</script>

README

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