How to use the midway-web.init function in midway-web

To help you get started, we’ve selected a few midway-web 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 / sandbox / packages / sandbox-core / src / core / dataSource / base.ts View on Github external
import { init } from 'midway-web';
import { Sequelize } from 'sequelize';
import { Options as SequelizeOptions, Sequelize as SequelizeInstance } from 'sequelize';

export class BaseDataSource {
  protected instance: SequelizeInstance;

  protected config;
  protected logger;
  protected name: string;

  @init()
  async connection() {
    const password = await this.getPassword();
    const options: SequelizeOptions = this.getOptions();
    const database: string = this.config.database;
    const username: string = this.config.username;

    this.instance = new Sequelize(database, username, password, options);

    try {
      await this.instance.authenticate();
      await this.prepare();
    } catch (error) {
      error.message = `[DataSource-${this.name}] connection error:${error.message}`;
      throw error;
    }
  }
github midwayjs / sandbox / packages / sandbox-core / src / core / manager / traceNodeManager.ts View on Github external
@provide('traceNodeManager')
export class TraceNodeManager {

  @inject()
  protected dw;

  @logger()
  protected logger;

  @inject()
  protected traceNodeModel;

  protected instance;

  @init()
  initialize() {
    this.instance = this.dw.instance;
  }

  escape(query: object, fields: string[]): void {
    fields.forEach((field) => {
      if (query[field] !== undefined) {
        query[field] = this.instance.escape(query[field]);
      }
    });
  }

  public async list(condition: FindOptions): Promise> {
    return this.traceNodeModel.findAndCount(condition);
  }
github midwayjs / sandbox / packages / sandbox-core / src / core / dataSource / tsdb.ts View on Github external
@logger()
  public logger;
  defaultQueryOpts = {
    ms: 'true',
  };
  defaultPOSTOpts = {
    msResolution: true,
    showQuery: false,
  };

  protected host: string;
  protected port: string;
  protected prefix: string;

  @init()
  init() {
    this.host = this.config.host;
    this.port = this.config.port;
    this.prefix = 'http://' + this.host + ':' + this.port;
  }

  async suggest(suggestOptions: SuggestOptions) {
    const resp = await this.request('/api/suggest', suggestOptions, {
      method: 'GET',
    });
    return resp.data;
  }

  async query(queryOptions: QueryOptions): Promise {
    const resp = await this.requestPost('/api/query', {
      data: {
github midwayjs / sandbox / packages / sandbox-core / src / core / manager / traceManager.ts View on Github external
import {sqlPartTimestampConvertToTs} from '../util/util';

@provide('traceManager')
export class TraceManager {

  @logger()
  protected logger;

  @inject()
  protected dw;

  @inject()
  protected traceModel;
  protected instance;

  @init()
  initialize() {
    this.instance = this.dw.instance;
  }

  escape(query: object, fields: string[]): void {
    fields.forEach((field) => {
      if (query[field] !== undefined) {
        query[field] = this.instance.escape(query[field]);
      }
    });
  }

  async list(condition: FindOptions): Promise> {
    return this.traceModel.findAndCount(condition);
  }