lichang-egg-sequelize-auto
v0.1.1
Published
Automatically generate bare sequelize models from your database, adjustment for egg
Downloads
2
Readme
Egg-Sequelize-Auto
Automatically generate models for egg-sequelize via the command line.
NOTE: Egg-Sequelize-Auto is based on Sequelize-Auto.
Why Egg-Sequelize-Auto
Sequelize-Auto
is a tool used to generate models for Sequelize, which based on old Sequelize
version 3.x.
Now, Sequelize v4
has breaking changes, we need a latest version of Sequelize-Auto
which works in Egg.
So we upgraded Sequelize-Auto
to Sequelize
v4 and adjusted it for egg-sequelize.
Install
npm install -g egg-sequelize-auto
Prerequisites
You will need to install the correct dialect binding globally before using egg-sequelize-auto.
Example for MySQL/MariaDB
npm install -g mysql2
Example for Postgres
npm install -g pg pg-hstore
Example for Sqlite3
npm install -g sqlite3
Example for MSSQL
npm install -g mssql
create model.js
`vi model.js`
const SequelizeAuto = require('sequelize-auto')
const path = require('path')
const auto = new SequelizeAuto(config.database, config.user, config.password, {
host: config.host,
dialect: config.dialect,
directory: path.resolve(__dirname, '../model_tmp'),
camelCase: true,
logging: function () {},
additional: {
timestamps: false,
}
})
auto.run(err => {
if (err) {
return console.log(err)
} else {
console.log('model 文件生成')
}
})