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 🙏

© 2024 – Pkg Stats / Ryan Hefner

models-generator-express-nestjs

v1.0.10

Published

<h1 align="center"> <div align="center"> <img src="https://raw.githubusercontent.com/geranjian2/models-generator-express-nestjs/develop/media/logo-generators.png" width="600" alt="NestJS Express Generators Logo" /> </div> </h1>

Downloads

4

Readme

Features

  • Config file generate models
  • Support for nestjs and express ts
  • Generate models, interface, entities, dto from your database postgres

package install

  $ npm i  @nestjs/swagger dotenv

Installation

NPM

$ npm i  models-generator-express-nestjs

Getting started

Once the installation process is complete, create file config in the root project for generate models

 

File configuration

const models = require('models-generator-express-nestjs/src/index')
require('dotenv').config()
const main = async () => {
    const connection = {
      host: process.env.DATABASE_HOST || 'localhost',
      port: process.env.DATABASE_PORT || '5432',
      user: process.env.DATABASE_USER || 'user_db',
      password: process.env.DATABASE_PASSWORD || 'pass_db',
      database: process.env.DATABASE || 'your_database'
    };

    const config = {
    database:'mysql', //mysql | postgres 
    orm: 'SEQUELIZE', // TYPEORM | SEQUELIZE,
    configMigrations: true,
    installPackage:true,
    outputModelFile: '.app/modules/',
    tables: {
      exclude: '',
      include: '',
    },
    auth:{
      generate:true,
      table: 'users',
      fields:{
        user:'email',
        password:'password',
      },
      uninstallPackage:false
    },
    generatorForModule: {
      dto: true,
      models: true,
      entitie: true,
      interface: true,
      module: true,
      controller: true,
      rest: true,
      service: true,
    },
    deleteAlways:true
  };

    const modelsPromise = await models(connection.database, connection, config);
    const all = await Promise.all([modelsPromise]);
    process.exit();
}

Add command package.json

 "generator": "node main.js"

Running

npm run generator

json config paramters description

database

  • Select database mysql or postgress

orm

  • Select orm sequelize or typeorm

configMigrations true | false

  • configure in the json package the necessary commands to run migrations

installPackage true | false

-Depending on the orm you select, it will install the corresponding packages

#package typeorm
  -typeorm
  -@nestjs/typeorm
  -@nestjs/config

#package sequelize
  -sequelize
  -sequelize-typescript
  -@nestjs/sequelize

outputModelFile

  • path where the modules will be created

tables

  • configuration to exclude or include tables in the generation of modules

exclude

-tables not included

include

-tables that only include

auth

  • We can generate a login from a table and its respective field of username and password

generate true | false

-validate if we are going to generate the auth module

table

-name of the table where the auth module will be generated

fields

- username and password fields for login
### user
### password

generatorForModule

dto true | false

models true | false

entitie true | false

interface true | false

module true | false

controller true | false

rest true | false

service true | false

deleteAlways true | false

  • 📢 important this parameter should only be in tru only in the initial part of the generator then it should be left in false, it already eliminates the folders

Example modules generators sequelize

├── ./app
│   └── main.ts
│   └── app.module.ts
│   ├── modules
│   │   ├── users
│   │   │   ├── dtos
│   │   │   │   ├── user.dto.ts
│   │   │   ├── entities
│   │   │   │   ├── user.entity.ts
│   │   │   ├── interface
│   │   │   │   ├── user.interface.ts
│   │   │   ├── models
│   │   │   │   ├── user.model.ts
│   │   │   ├── rest
│   │   │   │   ├── user.json
│   │   │   ├── user.service.ts
│   │   │   ├── user.module.ts
│   │   │   ├── user.controller.ts
│   ├── database
│   │   ├── database.models.ts
│   │   ├── database.module.ts
│   │   ├── database.providers.ts
│   │   ├── sequalize.constants.ts
│   │   └── modules.providers.ts
│   ├── sequelize
│   │   ├── config
│   │   │   ├── config.js
│   │   ├── migrations
│   │   └── seeders

Example modules generators typeorm

├── ./app
│   └── main.ts
│   └── app.module.ts
│   ├── modules
│   │   ├── users
│   │   │   ├── dtos
│   │   │   │   ├── user.dto.ts
│   │   │   ├── entities
│   │   │   │   ├── user.entity.ts
│   │   │   ├── interface
│   │   │   │   ├── user.interface.ts
│   │   │   ├── models
│   │   │   │   ├── user.model.ts
│   │   │   ├── rest
│   │   │   │   ├── user.json
│   │   │   ├── user.service.ts
│   │   │   ├── user.module.ts
│   │   │   └── user.controller.ts
│   ├── config
│   │   ├── config.typeorm.module.ts
│   │   ├── database.typeorm.config.ts
│   │   └── migrations.typeorm.config.ts
│   ├── typeorm
│   │   └── migrations

File configuration .env

 TYPE_CONNECTION=mysql
 DATABASE_PORT=3306
 DATABASE_HOST=localhost
 DATABASE_USER=root
 DATABASE_PASSWORD=admin
 DATABASE=payment_backoffice

# generate orm is sequelize, add variables
 DATABASE_DIALECT=mysql
 DATABASE_SCHEMA=public
 DATABASE_LOGGING=true
 NODE_ENV=development

 #generate auth is true, add variable
 JWT_SECRET='mysecret'