Commit 853786b2 authored by nanahira's avatar nanahira

readme

parent 62d28c7f
...@@ -22,46 +22,53 @@ Those decorators would all decorate the following, with the SAME settings. ...@@ -22,46 +22,53 @@ Those decorators would all decorate the following, with the SAME settings.
@Entity() @Entity()
export class User extends IdBase() { export class User extends IdBase() {
@Index() @Index()
@QueryLike() // queries as 'where name LIKE :name%'
@StringColumn(5, { @StringColumn(5, {
required: true, required: true,
description: 'User name', description: 'User name',
}) })
name: string; name: string;
@QueryEqual() // queries as 'where age = :age'
@IntColumn('int', { unsigned: true, description: 'User age', default: 20 }) @IntColumn('int', { unsigned: true, description: 'User age', default: 20 })
age: number; age: number;
@EnumColumn(Gender, { description: 'User gender' }) @EnumColumn(Gender, { description: 'User gender' })
gender: Gender; gender: Gender;
@NotColumn() @NotColumn()
somethingElse: any; // Would not come from client input, and would not go into OpenAPI document. somethingElse: any; // Would not come from client input, and would not go into OpenAPI document.
// possible optional override operations // possible optional override operations
override isValidInCreate() { // Custom before-create check. override isValidInCreate() { // Custom before-create check.
if (!this.name.length) { if (!this.name.length) {
return 'Name cannot be empty!'; return 'Name cannot be empty!';
} }
} }
override isValidInUpdate() { // Custom before-update check. override isValidInUpdate() { // Custom before-update check.
if (this.name && !this.name.length) { if (this.name && !this.name.length) {
return 'Name cannot be empty!'; return 'Name cannot be empty!';
} }
} }
override async beforeCreate() { override async beforeCreate() {
this.name = this.name.toLowerCase(); // Do something before create. this.name = this.name.toLowerCase(); // Do something before create.
} }
override async afterCreate() { override async afterCreate() {
this.name = this.name.toUpperCase(); // Do something after create before sending to user. this.name = this.name.toUpperCase(); // Do something after create before sending to user.
} }
override async beforeGet() {} override async beforeGet() {
override async afterGet() {} }
override async beforeUpdate() {}
override async afterGet() {
}
override async beforeUpdate() {
}
} }
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment