npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sequelize-mg

v2.1.1

Published

A customizable sequelize model generation tool

Downloads

16

Readme

sequelize-mg

node version NPM version npm download

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.

中文说明

Prerequisites

  • node >=8

Install

npm i sequelize-mg

Usage

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

Config

| 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 |

Default configuration

The external incoming configuration will be merged with the default configuration, you can view the default configuration in [here] (./lib/default)

Run tests

npm i sequelize-auto
npm i mysql
npm run test

Author

985ch

License

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