-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# midway-base | ||
|
||
我的想法是根据TypeORM模型定义,快速生成crud | ||
|
||
1)配置数据源 | ||
|
||
``` | ||
{ | ||
type: 'mysql', | ||
host: '127.0.0.1', | ||
port: 3306, | ||
username: 'root', | ||
password: '', | ||
database: 'demo', | ||
synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true,注意会丢数据 | ||
logging: true, | ||
} | ||
``` | ||
|
||
2)定义模型 | ||
|
||
比如定义如下 | ||
|
||
``` | ||
{ | ||
User:{ | ||
name: string, | ||
username: string, | ||
email: string, | ||
phone: string, | ||
website: string, | ||
company: string, | ||
}, | ||
Post:{ | ||
name: string, | ||
title: string, | ||
body: string, | ||
userId: User.id, | ||
} | ||
} | ||
``` | ||
|
||
如果想定制,可以扩展属性。 | ||
|
||
``` | ||
{ | ||
User:{ | ||
name: string, | ||
username: { | ||
type: string, | ||
nullable: true, | ||
default: "i5ting" | ||
}, | ||
} | ||
} | ||
``` | ||
|
||
3)执行命令,生成代码 | ||
|
||
> $ base abc.json | ||
4)预览 | ||
|
||
> $ npm run dev | ||