Sequelize.js 如何从 MySQL 映射 varbinary 类型 [英] Sequelize.js how to map a varbinary type from MySQL

查看:43
本文介绍了Sequelize.js 如何从 MySQL 映射 varbinary 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Sequelize.js 来映射 MySQL 表中的所有列.

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

mysql 表用户"有一个密码列,类型为 varbinary(50).

The mysql table "User" has a Password column as type varbinary(50).

Sequelize.js 是否支持 varbinary 类型的映射?我在 Sequelize docs 中没有看到这样的选项,还有其他方法可以映射它吗?

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?

推荐答案

sequelize 中的内置类型只是映射到字符串,因此:

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)'
});

仅当您希望 sequelize 为您创建表格时才需要这样做 (sequelize.sync()),如果您使用的是预先创建的表格,那么您编写的类型无关紧要.唯一的例外是如果您使用 Sequelize.BOOLEAN 类型,它将 0 和 1 转换为它们的布尔值.

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.

这篇关于Sequelize.js 如何从 MySQL 映射 varbinary 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆