How to use the midway.async function in midway

To help you get started, we’ve selected a few midway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / midway-examples / demo-sequelize / src / lib / model / db.ts View on Github external
import { async, config, init, provide, scope, ScopeEnum } from 'midway';
import { Options, Sequelize } from 'sequelize';

export interface IDBOptions extends Options {
  database: string;
  username: string;
  password: string;
}

export interface IDB {
  sequelize: Sequelize;
  options: IDBOptions;
}
@scope(ScopeEnum.Singleton)
@async()
@provide('DB')
export default class DB implements IDB {
  public sequelize: Sequelize;

  @config('sequelize')
  public options: IDBOptions;

  @init()
  public connect() {
    this.sequelize = new Sequelize(
      this.options.database,
      this.options.username,
      this.options.password,
      {
        dialect: this.options.dialect,
        host: this.options.host,

midway

A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade.

MIT
Latest version published 3 years ago

Package Health Score

60 / 100
Full package analysis