Repository navigation
modules_model
Rafael Corrêa Chaves edited this page Jul 18, 2021
·
1 revision
Models are a easy way to group your data with methods to format it, save and other crud operations.
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;
}// 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();- 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
Copyright (c) 2021 APO Softworks. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.