Amc_rtty Amc_rtty -4 years ago 228
Node.js Question

Sequelize.js how to map a varbinary type from MySQL

I am trying to use Sequelize.js to map all of the columns in my MySQL table.

The mysql table "User" has a Password column as type


Does Sequelize.js support mapping for a varbinary type? I did not see such an option in the Sequelize docs, is there another way I can map it?

Answer Source

The built-in types in sequelize just maps to strings, so intead of:

User = sequelize.define('user', {
  Password: Sequelize.STRING

You can write your own string like this:

User = sequelize.define('user', {
  Password: 'VARBINARY(50)'

This is only necessary if you want sequelize to create your table for you (sequelize.sync()), if you are using pre-created tables it does not matter what you write as the type. The only exception to this is if you are using the Sequelize.BOOLEAN type, which converts 0 and 1 to their boolean value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download