forked from sidorares/node-mysql2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-charset-mapping.js
50 lines (40 loc) · 1.31 KB
/
generate-charset-mapping.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const mysql = require('../index.js');
const conn = mysql.createConnection({
user: 'mycause_dev',
password: 'mycause'
});
const iconv = require('iconv-lite');
const charsets = [];
// TODO: add encodings missing in iconv-lite
// "dec8","hp8","swe7","keybcs2","utf32","geostd8"
// see also https://github.com/ashtuchkin/iconv-lite/issues/125
// https://en.wikipedia.org/wiki/Kamenick%C3%BD_encoding
// https://github.com/twitter/mysql/tree/master/sql/share/charsets
// https://github.com/sidorares/node-mysql2/pull/772
const mysql2iconv = {
utf8: 'cesu8',
utf8mb4: 'utf8',
utf16le: 'utf16-le',
ujis: 'eucjp',
// need to check that this is correct mapping
macce: 'macintosh' // Mac Central European
};
const missing = {};
conn.query('show collation', (err, res) => {
console.log(res);
res.forEach(r => {
const charset = r.Charset;
const iconvCharset = mysql2iconv[charset] || charset; // if there is manuall mapping, override
if (!iconv.encodingExists(iconvCharset)) {
missing[iconvCharset] = 1;
}
charsets[r.Id] = iconvCharset;
});
//console.log(JSON.stringify(missing, 4, null));
//console.log(JSON.stringify(charsets, 4, null));
for (let i = 0; i < charsets.length; i += 8) {
console.log(` '${charsets.slice(i, i + 8).join("', '")}',`);
}
});
conn.end();