Utils / Lodash.js

Sequelize comes with some handy utils including references to lodash as well as some individual helpers. You can access them via Sequelize.Utils.

You can access all the methods of lodash like this:

Sequelize.Utils._.each(/* ... */)
Sequelize.Utils._.map(/* ... */)
Sequelize.Utils._...

Check out the Lodash page for further information.

Compatibility

Sequelize is compatible to the following versions of Node.JS:

  • 0.8.x
  • 0.10.x

Asynchronicity

Sincev1.3.0there are multiple ways of adding listeners to asynchronous requests. First of all, each time you call a finder method or save an object, sequelize triggers asynchronous logic. To react to the success or the failure (or both) of the request, you can do the following:

// the old, pre-v1.3.0 way
Model.findAll().on('success', function(models) { /* foo */ })
Model.findAll().on('failure', function(err) { /* bar */ })
 
// the new, >=v1.3.0 way
// each one is valid
Model.findAll().on('success', function(models) { /* foo */ })
Model.findAll().success(function(models) { /* foo */ })
Model.findAll().ok(function(models) { /* foo */ })
 
// Model.findAll().on('failure', function(err) { /* bar */ }) ==> invalid since v1.5.0
Model.findAll().on('error', function(err) { /* bar */ }) //   ==> new since v1.5.0
Model.findAll().error(function(err) { /* bar */ })
Model.findAll().failure(function(err) { /* bar */ })
Model.findAll().fail(function(err) { /* bar */ })
 
Model.findAll().complete(function(err, result) { /* bar */ })
Model.findAll().done(function(err, result) { /* bar */ })
 
// As of 1.7.0 we support Promises/A
var self = User
 
user.find(1).then(function(user1) {
  return user1.increment(['aNumber'], 2)
}).then(function(user2) {
  return user.find(1)
}).then(function(user3) {
  console.log(user3.aNumber) // 2
}, function(err) {
  // err...
})
 
 
// For functions with multiple success values (e.g. findOrCreate) there is also spread
 
user.findOrCreate(...).spread(function(user, wasCreated) {
  // all arguments are passed
})
user.findOrCreate(...).then(function(user) {
  // only the first argument is passed
})

Please notice:Since v1.5.0 the 'error' event is used to notify about errors. If such events aren't caught however, Node.JS will throw an error. So you would probably like to catch them :D

If you want to keep track about latest development of sequelize or to just discuss things with other sequelize users you might want to take a look at the following resources:

Companies & Projects

Here is a list of companies and projects that are using Sequelize in real world applications:

Shutterstock

Shutterstock Images LLC is a leading global provider of high-quality stock footage, stock photography, vectors and illustrations to creative industry professionals around the world. Shutterstock works closely with its growing contributor community of artists, photographers, videographers and illustrators to curate a global marketplace for royalty-free, top-quality imagery. Shutterstock adds tens of thousands of rights-cleared images and footage clips each week, with more than 18 million files currently available.

Clevertech

Clevertech builds web and mobile applications for startups using Lean and Agile methodologies. Clevertech relies on Sequelize for its applications, its speed, versatility and data flexibility. Clevertech contributes back to open source development and its expert developers support the continuing effort to make sequelize the best ORM for Node projects.

Metamarkets

Metamarkets enables buyers and sellers of digital media to visualize insights and make decisions with real-time pricing, performance, and audience data.

filsh

filsh allows you to download online videos from various video portals like YouTube, Vimeo and Dailymotion in a format you like. No software required.

Using sequelize?

If you want to get listed here, just drop me a line or send me a pull-request on Github!