-
Notifications
You must be signed in to change notification settings - Fork 21
Description
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:
- sequelize 6 is not supported. For example,
DataTypes.INTEGER(10)isDataTypes.INTEGER({ length: 10})in V6 - since I have so many tables, I would need the associations being generated as well.
.d.tsfiles are actually required for JS modules that can be consumed by typescript code. If the code is already in TS, the interface definitions would go directly into the.tsfiles- the models are lacking the generic type.
sequelize.define(..)returns a model with its internal type beingany. A slightly better solution would be to pass in the generics that are generated in the.d.tsfiles, sosequelize.define<MyModelAttributes,>(..), BUT ... sequelize.define()is one of the two ways you can define a model, but since I want to add custom functions to my models, I actually want to have a class on which I would callinit:
// I have timestamps on most of my tables, so I have an interface for the timestamp fields
export interface UserAttributes extends CreateableModel, ModifiableModel {
userId: number
name: string
}
// 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<User>
// 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 or EJS 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)