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

sequelize-generator-schematic

v1.1.1

Published

Sequelize entity model generator.

Downloads

31

Readme

Sequelize Generator Schematic

Aimed to make code generation a little simpler, this command line tool generates Typescript code for Sequelize entity model classes.

The sequelize-generator schematic doesn't generate all the desired table structure, but most of the code required to make nice database models based on some copy & pasting process.

The entitytype-generator schematic generates a sequelize-less "type" class, that can be used elsewhere (frontend or other backend classes).

Installation

From cloning the repo

Execute:

git clone [email protected]:jsanta/sequelize-generator.git
cd sequelize-generator
npm install
npm run build
cd <your project folder>
npm link <sequelize-generator folder>

From NPM

Execute:

npm i sequelize-generator-schematic

Usage

The sequelize-generator schematic

From the command line, execute:

ng g sequelize-generator-schematic:sequelize-generator --project=<project_name> <path> --flat --schema=<the database schema for the table>

Parameter explanation:

  • --project=< project > : receives the project name, for example if you are working on a monorepo, or have multiple projects defined on your angular json. This is optional and if not defined it will take the first project it find on the angular.json file
  • < path > : should be the relative path where you want the model file to be generated. The schematic will take the file name and use it as the ClassName, modelName and table_name.
  • --flat : No other folders will be created to contain the file.
  • --schema=< schema > : Database schema for the table. Defaults to public

The entitytype-generator schematic

From the command line, execute:

ng g sequelize-generator-schematic:entitytype-generator --project=<project_name> --flat <path>

Parameter explanation:

  • --project=< project > : receives the project name, for example if you are working on a monorepo, or have multiple projects defined on your angular json. This is optional and if not defined it will take the first project it find on the angular.json file
  • < path > : should be the relative path where you want the type class file to be generated. The schematic will take the file name and use it as the TClassName and the implemented IInterface.
  • --flat : No other folders will be created to contain the file.

These type classes generated by the schematic require some extra objects from the so called 'utils' module. You can find this module in the schematic source.

IMPORTANT

Editing the generated files is absolutely required.
For EntityValidators to work you'll need to run first:
npm install --save ajv typescript-json-schema

Beware: Large database models that consider multiple different schemas can lead to class collisions (user table, named as user, in different schemas, each table with a sightly different struncture (believe me, it happens...)). Be sure to name your classes in an intelligent way to avoid errors due to name collisions (eg schemaCache caching the wrong json-schema => wrong validations).


Contact me at:

e-Mail: j [at] santa dot cl
Twitter: @JSantaCL
Medium: https://medium.com/@jsantacl