
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
sequelize-mg
Advanced tools
This package provides the function of generating the sequelize model file according to the table, supports partial update files and custom generated file formats, and some codes refer to sequelize-auto.
npm i sequelize-mg
The following is an example of creating a mysql correspondence table using sequelize-auto. Please confirm that the ./models/ directory already exists.
'use strict';
const AutoSequelize = require('sequelize-auto');
const sequelizeGen = require('./');
const auto = new AutoSequelize('database', 'yourname', 'yourpass', {
dialect: 'mysql',
directory: false, // we don't use sequelize-auto to generate model files
define: {
timestamps: false,
freezeTableName: true,
},
});
auto.run().then(data => {
const tables = {};
for (const tableName in data.tables) {
const table = data.tables[tableName];
for (const fieldName in table) {
const field = table[fieldName];
field.isSerialKey = field.foreignKey;
}
tables[tableName] = { columns: table, comment: 'sample' };
}
sequelizeGen(tables, { dialect: 'mysql' });
});
You can also get tables in other ways, and generate your own model files with your own defined info like this.
const sequelizeGen = require('sequelize-mg');
const { tables, info, config} = yourDatabaseReader(params);
sequelizeGen(tables, info, config); // Note: The default v2t function requires info.dialect to be present and is a string
| name | format | description |
|---|---|---|
| dir | string | Specify the storage path of the model file. The default value is './models'. |
| gfn | (table)=>'' | GenerateFileName,Generate a file name based on the table name. By default, the table name is the file name. |
| gt | (table, fields, comment, info, config)=>'' | GenerateTable,Generate text for the replaceable area, where fields are already processed text |
| f2t | (table, field, obj, info, config)=>'' | FieldToText,Generate field text for the table |
| t2t | (table, field, obj, info, config)=>'' | TypeToText,Generate type text and return, the result is stored to obj.typeText |
| v2t | (table, field, obj, info, config)=>'' | defaultValueToText,Generate defaultValue text and return, return the result to obj.defaultValText |
| flagBegin | string | The starting point for marking the replaceable area |
| flagEnd | string | Used to mark the end point of the replaceable area. When updating the model file, only the part between the start point and the end point will be replaced. |
| lf | string | Newline, default is '\n' |
| sequelizeText | string | The corresponding text of the sequelize object, only for replaceable areas |
| fileHead | string | File header, the part before the replaceable area, only valid when creating a new model file |
| fileTail | string | End of file, the part after the replaceable area, only valid when creating a new model file |
| fileOptions | any | Options when reading and writing files, defaults to 'utf8' |
| rewrite | boolean | Force the entire file to be regenerated, the default is false |
| notice | (name, table, flag)=>null | If you configure this parameter, call this method after generating the model |
The external incoming configuration will be merged with the default configuration, you can view the default configuration in [here] (./lib/default)
npm i sequelize-auto
npm i mysql
npm run test
985ch
Copyright © 2019 985ch.
This project is MIT licensed.
This README was translate by google
FAQs
A customizable sequelize model generation tool
We found that sequelize-mg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.