Amc_rtty
Amc_rtty

Reputation: 3813

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 varbinary(50).

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?

Upvotes: 1

Views: 3724

Answers (1)

Jan Aagaard Meier
Jan Aagaard Meier

Reputation: 28798

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.

Upvotes: 7

Related Questions