search

Home  >  Q&A  >  body text

node.js - sequelize如何插入emoji表情?

问题描述

MySQL的shell中可以添加emoji表情,但是使用sequelize就不行了。

表中带???的就是使用sequelize插入的数据,带emoji的是在shell中手动插入的。

sequelize配置:

var sequelize = new Sequelize(mysql_db, mysql_user, mysql_passwd,{
    host: mysql_host,
    dialect: 'mysql',
    dialectOptions: {
        charset: "utf8mb4",
        collate: "utf8mb4_unicode_ci",
        supportBigNumbers: true,
        bigNumberStrings: true
    },
    pool: {
        max: 5,
        min: 0,
        idle: 10000
    }
});
    

相关模块版本:

    "redis": "^2.6.2",
    "sequelize": "^3.24.0",
迷茫迷茫2783 days ago628

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 15:48:59

    Thanks for the invitation.
    It should be an encoding problem. node.js must use utf-8 encoding, while emoji is unicode encoding. So there will be?? appear.
    It is recommended that you code and store it in the database. Then just decode it when you use it. The encoding method is base64.

    reply
    0
  • Cancelreply