Skip to content

torns/egg-typeorm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

egg-typeorm

TypeORM plugin for Egg.js.

NOTE: This plugin supports TypeScript only.

NPM version build status npm download

Install

$ yarn add @forsigner/egg-typeorm mysql

Usage

// {app_root}/config/plugin.ts
const plugin: EggPlugin = {
  typeorm: {
    enable: true,
    package: '@forsigner/egg-typeorm',
  },
}

Configuration

// {app_root}/config/config.default.ts
config.typeorm = {
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'test',
  password: 'test',
  database: 'test',
  synchronize: true,
  logging: false,
  entities: ['app/entity/**/*.ts'],
  migrations: ['app/migration/**/*.ts'],
  subscribers: ['app/subscriber/**/*.ts'],
}

// in controller
export default class UserController extends Controller {
  public async index() {
    const { ctx } = this;
    ctx.body = await ctx.model.User.find();
  }
}

Example

example

Questions & Suggestions

Please open an issue here.

License

MIT