@acai/model
TypeScript icon, indicating that this package has built-in type declarations

0.8.0-beta.22 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @acai/model

Weekly Downloads

0

Version

0.8.0-beta.22

License

BSD-3-Clause

Unpacked Size

158 kB

Total Files

10

Last publish

Collaborators

  • darklight98