@eggjs/tegg-orm-decorator
TypeScript icon, indicating that this package has built-in type declarations

3.32.0 • Public • Published

@eggjs/tegg-orm-decorator

Install

npm i --save @eggjs/tegg-orm-decorator

Define Model

import { Model, Attribute } from '@eggjs/tegg-orm-decorator';
import { DataTypes, Bone } from 'leoric';

@Model()
export class App extends Bone {
  @Attribute(DataTypes.STRING)
  name: string;
  @Attribute(DataTypes.STRING)
  desc: string;
}

Use Model

import { SingletonProto, Inject } from '@eggjs/tegg';
import { App } from './model/App';

@SingletonProto()
export class AppService {
  @Inject()
  App: typeof App;

  async createApp(data: {
    name: string;
    desc: string;
  }): Promise<App> {
    const bone = await this.App.create(data as any);
    return bone as App;
  }

  async findApp(name: string): Promise<App | null> {
    const app = await this.App.findOne({ name });
    return app as App;
  }
}

Package Sidebar

Install

npm i @eggjs/tegg-orm-decorator

Weekly Downloads

271

Version

3.32.0

License

MIT

Unpacked Size

36.9 kB

Total Files

31

Last publish

Collaborators

  • gxkl
  • gemwuu
  • eggjs-admin
  • fengmk2
  • atian25
  • dead_horse
  • wanghx
  • hyj1991
  • killagu
  • coolme200
  • mansonchor.zzw
  • hubcarl