Sequelize.js how to map a varbinary type from MySQL

不问归期 提交于 2019-12-24 13:46:47

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13888689/sequelize-js-how-to-map-a-varbinary-type-from-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!