biggora / caminte

Cross-db ORM for NodeJS
http://www.camintejs.com/
MIT License
1.08k stars 119 forks source link

Can't setup utf8mb4 instead utf8 for mysql connection #170

Closed SashaDesigN closed 5 years ago

SashaDesigN commented 6 years ago

Before read below - CaminteJS you have no support of charset property.

Hi! I change utf8 to utf8mb4 my mysql database and all working well on PHP but when I try to insert the same values using CaminteJS & mysql it fails with message:

 app:log Error: ER_INVALID_CHARACTER_STRING: Invalid utf8 character string: '\xF0\x9F\x9B\x8D'
  app:log     at Query.Sequence._packetToError (/service/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
  app:log     at Query.ErrorPacket (/service/app/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
  app:log     at Protocol._parsePacket (/service/app/node_modules/mysql/lib/protocol/Protocol.js:279:23)
  app:log     at Parser.write (/service/app/node_modules/mysql/lib/protocol/Parser.js:76:12)
  app:log     at Protocol.write (/service/app/node_modules/mysql/lib/protocol/Protocol.js:39:16)
  app:log     at Socket.<anonymous> (/service/app/node_modules/mysql/lib/Connection.js:103:28)

My connection code:

const caminte = require('caminte');

const Schema = caminte.Schema;
const config = {
     driver     : "mysql",
     host       : "localhost",
     port       : "3306",
     username   : "boost",
     password   : "12345",
     database   : "booster",
     pool       : true,
     charset    : 'utf8mb4_general_ci'
};

const schema = new Schema(config.driver, config);

Maybe can I do SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci and it will resolve my issue, but how can I do it or there is some other trick to do that?

Thanks a lot for any help, I spent 1 week to resolve this)

SashaDesigN commented 5 years ago

Fixed it already, it's on nodejs mysql module side, not caminte itself