nodejh / sequelize-automate

Automatically generate bare sequelize models from your database.
MIT License
116 stars 22 forks source link

ReferenceError: sequelize is not defined #21

Closed nodejh closed 4 years ago

nodejh commented 4 years ago
//@ts-nocheck
import { IApplicationContext, providerWrapper } from "midway";
import { DataTypes, Sequelize } from 'sequelize';
import { IDB } from './db';
export default async function setupModel(context: IApplicationContext) {
  const db: IDB = await context.getAsync('DB');
  const attributes = {
    id: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      defaultValue: null,
      primaryKey: true,
      autoIncrement: true,
      comment: "主键",
      field: "id"
    },
    gmtCreate: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      primaryKey: false,
      autoIncrement: false,
      comment: "创建时间",
      field: "gmt_create"
    },
    gmtModified: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
      primaryKey: false,
      autoIncrement: false,
      comment: "修改时间",
      field: "gmt_modified"
    },

  return db.sequelize.define("test", attributes, options);
}
providerWrapper([{
  id: "TestModel",
  provider: setupModel
}]);

type is egg or midway: ReferenceError: sequelize is not defined.