@eggjs/tegg-orm-decorator

tegg orm decorator

Usage no npm install needed!

<script type="module">
  import eggjsTeggOrmDecorator from 'https://cdn.skypack.dev/@eggjs/tegg-orm-decorator';
</script>

README

@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 { ContextProto } from '@eggjs/tegg';
import { App } from './model/App';

@ContextProto()
export class AppService {
  // TODO impl inject Bone for context
  App: typeof App = 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;
  }
}