# egg-sequelize-mg

> A customizable sequelize model generation tool for egg-sequelize

Latest version **2.0.3** (published 2022-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-sequelize-mg
pnpm add egg-sequelize-mg
yarn add egg-sequelize-mg
bun add egg-sequelize-mg
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2022-07-04 |
| First published | 2019-07-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 3 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | 985ch |
| Maintainers | 985ch |
| Keywords | egg, sequelize, model, generator, customizable |

## Links

- npm: https://www.npmjs.com/package/egg-sequelize-mg
- Repository: https://github.com/985ch/egg-sequelize-mg
- Homepage: https://github.com/985ch/egg-sequelize-mg#readme
- Issues: https://github.com/985ch/egg-sequelize-mg/issues
- npm.io page: https://npm.io/package/egg-sequelize-mg

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [sequelize](https://npm.io/package/sequelize.md) ^6.5.0
- [sequelize-mg](https://npm.io/package/sequelize-mg.md) ^2.1.1

## Recent versions

- 2.0.3 (latest) — 2022-07-04
- 2.0.2 — 2021-12-10
- 2.0.1 — 2021-12-10
- 2.0.0 — 2021-12-08
- 1.2.4 — 2021-03-23
- 1.2.3 — 2021-03-18
- 1.2.2 — 2021-03-16
- 1.2.1 — 2021-03-16
- 1.2.0 — 2021-03-16
- 1.1.4 — 2021-03-02
- 1.1.3 — 2021-02-26
- 1.1.2 — 2021-02-26
- 1.1.1 — 2021-01-21
- 1.1.0 — 2021-01-20
- 1.0.2 — 2019-10-28
- … 2 more at https://npm.io/package/egg-sequelize-mg/versions

## README

# egg-sequelize-mg
![node version][node-image]
[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]

[node-image]: https://img.shields.io/badge/node-%3E%3D8-blue.svg
[npm-image]: https://img.shields.io/npm/v/egg-sequelize-mg.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-sequelize-mg
[download-image]: https://img.shields.io/npm/dm/egg-sequelize-mg.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-sequelize-mg

> > This package allows the user to automatically generate the required sequelize model file based on the database configuration, based on [sequelize-mg](https://github.com/985ch/sequelize-mg) and [egg-sequelize](https://github.com/eggjs/egg-sequelize) was adapted.

### [中文说明](./README.zh_CN.md)
## Prerequisites

- node &gt;=8

## Install

```sh
npm i egg-sequelize-mg --save-dev
```
## Usage
```js
// {appRoot}/config/database/sequelize.js
'use strict';
module.exports = {
  datasources: [{
    delegate: 'maindb',
    baseDir: 'model/main',
    database: 'main',
    dialect: 'mysql',
    username: 'root',
    password: 'root',
    define: {
      timestamps: false,
      freezeTableName: true,
      underscored: true,
    },
  }, {
    delegate: 'testdb',
    baseDir: 'model/test',
    database: 'test',
    dialect: 'mysql',
    username: 'root',
    password: 'root',
    define: {
      timestamps: false,
      freezeTableName: true,
      underscored: true,
    },
  }],
};
```
```js
// {appRoot}/tools/model-generator.js
'use strict';

const path = require('path');
const generator = require('egg-sequelize-mg');
const config = require('../config/database/sequelize');

const tables = {
  testdb: [ 'table1', 'table2' ], // If you don't want to generate all the tables in the database, configure the whitelist here.
}

// Output files to the target directory using a simple format
generator.generate(config, tables, path.join(__dirname, '../app/'), { mysql: generator.readMysql });
```
If you want to see more examples, please see [here](./test.js). If you want to configure your own file format, please go to [sequelize-mg](https://github.com/985ch/sequelize-mg)

## Run tests

```sh
npm run test
```

## Author

 **985ch**

* Github: [@985ch](https://github.com/985ch)

## License

Copyright © 2019 [985ch](https://github.com/985ch).<br />
This project is [MIT](https://github.com/985ch/egg-sequelize-mg/blob/master/LICENSE) licensed.<br />
This README was translate by [google](https://translate.google.cn)

---
_Source: https://npm.io/package/egg-sequelize-mg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
