发布6.x

This commit is contained in:
小鹏 2023-03-08 17:10:57 +08:00
parent 06c8c7975d
commit fac7f82c3d

View File

@ -45,10 +45,12 @@
#### 修改数据库配置,配置文件位于`src/config/config.local.ts` #### 修改数据库配置,配置文件位于`src/config/config.local.ts`
数据库为 mysql(`>=5.7版本`)node 版本(`>=12.x`),首次启动会自动初始化并导入数据 数据库为 mysql(`>=5.7版本`)建议 8.0node 版本(`>=12.x`),首次启动会自动初始化并导入数据
```ts ```ts
orm: { typeorm: {
dataSource: {
default: {
type: 'mysql', type: 'mysql',
host: '127.0.0.1', host: '127.0.0.1',
port: 3306, port: 3306,
@ -58,9 +60,15 @@ orm: {
// 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失 // 自动建表 注意:线上部署的时候不要使用,有可能导致数据丢失
synchronize: true, synchronize: true,
// 打印日志 // 打印日志
logging: true, logging: false,
// 字符集 // 字符集
charset: 'utf8mb4', charset: 'utf8mb4',
// 是否开启缓存
cache: true,
// 实体路径
entities: ['**/modules/*/entity'],
},
},
}, },
``` ```
@ -83,14 +91,13 @@ $ open http://localhost:8001/
`src/modules/demo/entity/goods.ts`,项目启动数据库会自动创建该表,无需手动创建 `src/modules/demo/entity/goods.ts`,项目启动数据库会自动创建该表,无需手动创建
```ts ```ts
import { EntityModel } from '@midwayjs/orm';
import { BaseEntity } from '@cool-midway/core'; import { BaseEntity } from '@cool-midway/core';
import { Column } from 'typeorm'; import { Column, Entity, Index } from 'typeorm';
/** /**
* 商品 * 商品
*/ */
@EntityModel('demo_app_goods') @Entity('demo_app_goods')
export class DemoAppGoodsEntity extends BaseEntity { export class DemoAppGoodsEntity extends BaseEntity {
@Column({ comment: '标题' }) @Column({ comment: '标题' })
title: string; title: string;
@ -108,14 +115,12 @@ export class DemoAppGoodsEntity extends BaseEntity {
`src/modules/demo/controller/app/goods.ts`,快速编写 6 个 api 接口 `src/modules/demo/controller/app/goods.ts`,快速编写 6 个 api 接口
```ts ```ts
import { Provide } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core'; import { CoolController, BaseController } from '@cool-midway/core';
import { DemoAppGoodsEntity } from '../../entity/goods'; import { DemoAppGoodsEntity } from '../../entity/goods';
/** /**
* 商品 * 商品
*/ */
@Provide()
@CoolController({ @CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'], api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: DemoAppGoodsEntity, entity: DemoAppGoodsEntity,