nodejh / sequelize-automate

Automatically generate bare sequelize models from your database.
MIT License
115 stars 22 forks source link

Very general feedback (or why using template engines would be a better implementation) #40

Open hotaru355 opened 3 years ago

hotaru355 commented 3 years ago

Hi!

Fist of all, thank you for creating this repo! This is definitely more useful that the stale sequelize-auto repo out there. Unfortunately, it does not fully fit my bill. To give you some background: my project has about 300 MySql tables, with tables relating to each other in many-to-one and many-to-many relationships and the code is purely in typescript using sequelize version 6 (!). Using your very nicely written (:clap:) module gets me maybe 80% to were I would like to be, but unfortunately it lacks some flexibility. Here a short list:

// Your code is aware of optional fields, since it puts a "?" on those in the interface // It would be nice if it would create this second interface for sequelize export interface UserCreationAttributes extends Optional<UserAttributes, 'userId'> {}

// this is how I need the initialisation to work: create a class and call init() on it: class User extends Model<UserAttributes, UserCreationAttributes> implements UserAttributes { public userId!: number public name!: string public created!: Date public modified!: Date

public static function myCustomStaticFunc() {} public function myCustomInstanceFunc() {} }

// small improvement: sequelize provides a wrapper to create an interface for the static parts of the model. // Important though, it needs to be exported, since this is what I need everywhere in the code export type UserModel = ModelCtor

// the initialiser that is called on app startup export default (sequelize: Sequelize) => { const attributes = {...} const options = {...} // unfortunately, your script does not give my any control over these options like the timestamp for example User.init(attributes, options) }



Long story short, I would need some tweaks that are currently not supported. But instead of adding support for a lot of flags and switches to the `sequelize-automate.config.json`, I instead propose the following:

**Why not use a templating engine like [handlebars](https://handlebarsjs.com) or [EJS](https://ejs.co) internally and allow the user to provide their own templates!**

I believe this would give users the biggest flexibility, would be future-proof for new sequelize versions and any other changes, since it would just involve creating a new template to use.

What do you think ?! (sorry for my length explanations, I hope I did not waste your time)
nodejh commented 3 years ago

Hi @hotaru355 , thanks for your feedback, they are very valuable.

I will fix these issues, but may take a while.