@square-one/model-decorators
v1.0.9
Published
Model decorators that will allow for typescript classes to be built as models for ORM's and also be used within MVVM's like Angular 2 to build out custom elements.
Downloads
2
Readme
Model Decorators
Decorators that will allow for classes to be built as models for mongoose and also be used within client side frameworks like Angular 2 to build out custom elements.
Example
import { Field, FieldArray, Model, Method, StaticMethod } from "@add-io/model-decorators";
@Model("Example")
export class Example {
@Field({ required: true })
name: string;
@Field()
description: string;
@Field({ ref: "ExampleRef" })
example: ExampleRef;
@FieldArray(String, { required: true })
items: string[];
@FieldArray(ExampleRef, { ref: "ExampleRef" })
examples: ExampleRef[];
@Method()
save() {
// Do save method stuff...
}
@StaticMethod()
static loadExamples() {
// Load examples from the database...
}
}
@Model("ExampleRef")
export class ExampleRef {
@Field({ required: true })
name: string;
}
License
This library is under the MIT License