Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is patch to trick uuid field to force it store as BINARY field in mysql
- # In the model-definition
- # Try to define uuid id field
- `
- "id": {
- "type": "string",
- "defaultFn": "uuid",
- "id": true,
- "mysql": {
- "columnName": "user_id",
- "dataType": "BINARY",
- "dataLength": 16,
- "nullable": "N"
- }
- }
- `
- Inside function toColumnValue, replace
- `
- if (prop.type === String) {
- return String(val);
- }
- `
- with
- `
- if (prop.type === String) {
- const dataType = prop.mysql && prop.mysql.dataType || '';
- if (dataType.toUpperCase() === 'BINARY') {
- return Buffer.from(val.replace(/-/ig, ''), 'hex');
- }
- return String(val);
- }
- `
- Inside function fromColumnValue, replace
- `
- case 'String':
- val = String(val);
- break;
- `
- with
- `
- case 'String':
- const dataType = prop.mysql && prop.mysql.dataType || '';
- if (dataType.toUpperCase() === 'BINARY') {
- val = val instanceof Buffer ? val.toString('hex') : val;
- } else {
- val = String(val);
- }
- break;
- `
Add Comment
Please, Sign In to add comment