egg-sequelize-mg
v2.0.3
Published
A customizable sequelize model generation tool for egg-sequelize
Downloads
6
Maintainers
Readme
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 and egg-sequelize was adapted.
中文说明
Prerequisites
- node >=8
Install
npm i egg-sequelize-mg --save-dev
Usage
// {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,
},
}],
};
// {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. If you want to configure your own file format, please go to sequelize-mg
Run tests
npm run test
Author
985ch
- Github: @985ch
License
Copyright © 2019 985ch. This project is MIT licensed. This README was translate by google