2.0.3 • Published 2 years ago

egg-sequelize-mg v2.0.3

Weekly downloads
87
License
MIT
Repository
github
Last release
2 years ago

egg-sequelize-mg

node version NPM version npm download

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

License

Copyright © 2019 985ch. This project is MIT licensed. This README was translate by google

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago