New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sequelize-mg

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-mg

A customizable sequelize model generation tool

latest
Source
npmnpm
Version
2.1.1
Version published
Maintainers
1
Created
Source

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

nameformatdescription
dirstringSpecify 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
flagBeginstringThe starting point for marking the replaceable area
flagEndstringUsed 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.
lfstringNewline, default is '\n'
sequelizeTextstringThe corresponding text of the sequelize object, only for replaceable areas
fileHeadstringFile header, the part before the replaceable area, only valid when creating a new model file
fileTailstringEnd of file, the part after the replaceable area, only valid when creating a new model file
fileOptionsanyOptions when reading and writing files, defaults to 'utf8'
rewritebooleanForce the entire file to be regenerated, the default is false
notice(name, table, flag)=>nullIf 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

Keywords

sequelize

FAQs

Package last updated on 26 Feb 2021

Did you know?

Socket

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.

Install

Related posts