With Sequelize 1.0.0 the project was completly rewritten and had some major api changes, which will break your app, if you dont fix em. This post summarizes all changes and points out improvements and new features.

Logging

Disable logging of Sequelize is not longer realized via the options disableLogging:true, but with logging:false. So you now have to do this:

new Sequelize(config.database, config.username, config.password, { \ logging: false\ })

Chaining

Sequelize.chainQueries was replaced by Sequelize.Utils.QueryChainer. The API for that is:

new Sequelize.Utils.QueryChainer\ .add(person.save())\ .add(pet.save())\ .run()\ .on(success, function() { // done :) })

Instantiation

The instantiation of models has changed:

// Before\ new Model({attr1: 1, attr2: 2}).save()\ \ //Now\ Model.build({…}).save()\ // to first create the instance and save it afterwards or…\ \ Model.create({…})\ // to create it and directly write it to the database

Listeners

Sequelize changed from callback-driven to listener-driven architecture. So you now have to do

Model.create({a:1})\ .on(success, function(model){})\ .on(failure, function(err){})

instead of

new Model({a:1}).save(function(err, model) {})

Syncing

Syncing sequelize is the same way then before, but got some convenience:

//Before\ Sequelize.drop(function(){\ Sequelize.sync(function(){ })\ })\ \

//Now\ Sequelize.sync({force: true}).on(‘success’, function(){ })

New stuff / Other changes

Added a count method to Model:

Model.count().on(success, function(num) {})

Added option passing everywhere:

Model.count({where: {attr1: 1}})\ Model.find({where: {attr1: 1}})\ Model.findAll({where: {attr1: 1}})\ //….\ //Take a look at this for further information.

Added more options for Model definition: unique, primaryKey, autoIncrement. Take a look at this.

Some sequelize options have changed:

  • Don’t add timestamp attributes: timestamps: false
  • Don’t delete things from the database: paranoid: true
  • Use underscore names instead of camelcase: underscore: true
  • Don’t pluralize table names: freezeTableName: true

File import changed. The imported file should only return a single function. Take a look at the usage section on the Sequelize page.

The association API has changed. Please take a deeper look at this.

There might be more stuff, but I dunno them at the moment :D Have fun!

And btw. … expect more stuff in the future. I will write about sequelize in my master thesis :)