Binary fields in mySQL

I have a schema with ids stored as BINARY (sucks I know). Is it possible to write a plugin to convert them to string when receiving?
Solution:
You can use the typeCast config of mysql2 ```ts typeCast: function (field, next) { if (field.type === 'TINY' && field.length === 1) {...
Jump to solution
4 Replies
koskimas
koskimas15mo ago
Are you using the built-in MysqlDialect?
thelinuxlich
thelinuxlichOP15mo ago
yes solved it with
typeCast(field,next) {
if (field.type === 'BINARY') {
return field.string();
}
return next();
}
typeCast(field,next) {
if (field.type === 'BINARY') {
return field.string();
}
return next();
}
passing to createPool options
Solution
koskimas
koskimas15mo ago
You can use the typeCast config of mysql2
typeCast: function (field, next) {
if (field.type === 'TINY' && field.length === 1) {
return (field.string() === '1'); // 1 = true, 0 = false
} else {
return next();
}
}
typeCast: function (field, next) {
if (field.type === 'TINY' && field.length === 1) {
return (field.string() === '1'); // 1 = true, 0 = false
} else {
return next();
}
}
thelinuxlich
thelinuxlichOP15mo ago
thanks!
Want results from more Discord servers?
Add your server