Skip to content

can you support egg-typescript? #32

Description

@jtyjty99999

like code below

import { Application } from 'egg';

export default (app: Application) => {
  const DataTypes = app.Sequelize;
  const sequelize = app.model;
  const attributes = {
    id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: null,
      field: 'id',
      unique: 'uk_id',
    },
    name: {
      type: DataTypes.STRING(32),
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: 'user name',
      field: 'name',
    },
    email: {
      type: DataTypes.STRING(32),
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: 'user email',
      field: 'name',
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: 'created time',
      field: 'created_at',
    },
    updatedAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: 'update time',
      field: 'updated_at',
    },
  };
  const options = {
    tableName: 'user',
    comment: 'user table',
    indexes: [{
      name: 'uk_name_email',
      unique: true,
      fields: [
        'name',
        'email',
      ],
    }]
  };

  const UserModel = sequelize.define('userModel', attributes, options);
  return class extends UserModel {
    static associate() {
    }
  };
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions