sqlizr

1.2.0 • Public • Published

sqlizr

Automatically load Sequelize models via glob pattern.

Installation

npm i --save sqlizr

Usage

Define a model somewhere that is ready for Sequelize#import.

module.exports = function(sequelize, DataTypes) {
 
  var User = sequelize.define('User', {
    username: { type: DataTypes.STRING },
    password: { type: DataTypes.STRING }
  })
 
  User.associate = function(db) {
    User.hasMany(db.Posts)
  }
 
  return User
}
var sqlizr = require('sqlizr')
 
var sequelize = new Sequelize(...)
 
var db = sqlizr(sequelize, 'app/models/**/*.js')
 
db.User.find('mikefrey')

Associations

If you define an associate function on your model definition, sqlizr will run that function after all models have been loaded, passing in a hash of all loaded models for easy reference.

Setup any needed associations in the associate function, like shown in the example above.

Package Sidebar

Install

npm i sqlizr

Weekly Downloads

87

Version

1.2.0

License

MIT

Last publish

Collaborators

  • mikefrey