sequelize / express-example

A proposal for the usage of Sequelize within an Express.JS application.
MIT License
2.5k stars 770 forks source link

Why export Sequelize? #69

Closed psaeuerl closed 7 years ago

psaeuerl commented 7 years ago

I currently do not understand why Sequelize is exported in ./models/index.cs

db.Sequelize = Sequelize;

module.exports = db;

I do not see it used anywhere and from my current understanding, i do not know why it is exported here. PS: I´m quite new to sequelize and i´m trying to understand the sample.

Thanks in advance

sushantdhiman commented 7 years ago

You can get static methods like literal, and, fn etc which will be used when building queries, It also expose errors which can be accessed like db.Sequelize.UniqueConstraintError to catch errors

psaeuerl commented 7 years ago

Ahh thank you, this makes sense. So it is basically best-practice (if only one database is used) to export sequelize with it. Is the statement above valid?

sushantdhiman commented 7 years ago

If you need those methods or errors you can get them from model.sequelize.Sequelize.fn etc but thats too long for some guys. So its just a way to easily access required methods / errors

Its all up to you how you want to access it, shorter simpler way is better I guess