import { Controller, Get, Inject } from '@midwayjs/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; import { Context } from '@midwayjs/koa'; import { Photo } from '../entity/photo.entity'; import { Repository } from 'typeorm'; @Controller('/') export class HomeController { @Inject() ctx: Context; @InjectEntityModel(Photo) photoModel: Repository; @Get('/testMysql') async testMysql() { // create a entity object let photo = new Photo(); photo.name = 'Me and Bears'; photo.description = 'I am near polar bears'; photo.filename = 'photo-with-bears.jpg'; photo.views = 1; photo.isPublished = true; // save entity const photoResult = await this.photoModel.save(photo); // save success console.log('photo id = ', photoResult.id); this.ctx.body = photoResult.id; } }