|
1 | 1 | # sequelize-example
|
2 | 2 |
|
3 |
| -The [egg] example project that uses [egg-sequelize] plugin. |
| 3 | +The [egg] example project that uses [egg-sequelize] plugin. It will show you how to use sequelize in egg project, use [migrations] to help you manage changes of database and use [factory-girl] to help you write test cases more maintainable. |
4 | 4 |
|
5 | 5 | ## QuickStart
|
6 | 6 |
|
7 |
| -<!-- add docs here for user --> |
| 7 | +### Dependencies |
8 | 8 |
|
9 |
| -see [egg docs][egg] for more detail. |
| 9 | +- install mysql and create database |
10 | 10 |
|
11 |
| -### Development |
12 |
| -```bash |
13 |
| -$ npm install |
14 |
| -$ createdb example-dev --owner postgres |
15 |
| -$ npm run migrate:up |
16 |
| -$ npm run dev |
17 |
| -$ open http://localhost:7001/users |
18 | 11 | ```
|
| 12 | +brew install mysql # macOS |
| 13 | +brew service start mysql |
19 | 14 |
|
20 |
| -### Deploy |
| 15 | +mysql |
| 16 | + > create database `egg-sequelize-example-dev`; |
| 17 | + > create database `egg-sequelize-example-unittest`; |
| 18 | +``` |
| 19 | + |
| 20 | +- install dependencies |
| 21 | + |
| 22 | +``` |
| 23 | +npm install |
| 24 | +``` |
| 25 | + |
| 26 | +### Start Server and Run Test |
21 | 27 |
|
22 |
| -Use `EGG_SERVER_ENV=prod` to enable prod mode |
| 28 | +- prepare database structure |
23 | 29 |
|
24 |
| -```bash |
25 |
| -$ createdb example-prod --owner postgres |
26 |
| -$ NODE_ENV=production npm run migrate:up |
27 |
| -$ EGG_SERVER_ENV=prod npm start |
28 | 30 | ```
|
| 31 | +# for develop |
| 32 | +npm run sequelize -- db:migrate |
| 33 | +# for unittest |
| 34 | +NODE_ENV=test npm run sequelize -- db:migrate |
| 35 | +``` |
| 36 | + |
| 37 | +- start project |
29 | 38 |
|
30 |
| -### npm scripts |
| 39 | +``` |
| 40 | +npm run dev |
| 41 | +``` |
31 | 42 |
|
32 |
| -- Use `npm run lint` to check code style. |
33 |
| -- Use `npm test` to run unit test. |
34 |
| -- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail. |
| 43 | +- run test |
35 | 44 |
|
| 45 | +``` |
| 46 | +npm test |
| 47 | +``` |
36 | 48 |
|
37 | 49 | [egg]: https://eggjs.org
|
38 |
| -[egg-sequelize]: https://github.com/eggjs/egg-sequelize |
| 50 | +[egg-sequelize]: https://github.com/eggjs/egg-sequelize |
| 51 | +[sequelize]: http://docs.sequelizejs.com/ |
| 52 | +[migrations]: http://docs.sequelizejs.com/manual/tutorial/migrations.html |
| 53 | +[factory-girl]: https://github.com/aexmachina/factory-girl |
0 commit comments