Guest User

Untitled

a guest
Mar 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. # This is patch to trick uuid field to force it store as BINARY field in mysql
  2. # In the model-definition
  3. # Try to define uuid id field
  4. `
  5. "id": {
  6. "type": "string",
  7. "defaultFn": "uuid",
  8. "id": true,
  9. "mysql": {
  10. "columnName": "user_id",
  11. "dataType": "BINARY",
  12. "dataLength": 16,
  13. "nullable": "N"
  14. }
  15. }
  16. `
  17.  
  18. Inside function toColumnValue, replace
  19. `
  20. if (prop.type === String) {
  21. return String(val);
  22. }
  23. `
  24. with
  25. `
  26. if (prop.type === String) {
  27. const dataType = prop.mysql && prop.mysql.dataType || '';
  28. if (dataType.toUpperCase() === 'BINARY') {
  29. return Buffer.from(val.replace(/-/ig, ''), 'hex');
  30. }
  31. return String(val);
  32. }
  33. `
  34.  
  35. Inside function fromColumnValue, replace
  36. `
  37. case 'String':
  38. val = String(val);
  39. break;
  40. `
  41. with
  42. `
  43. case 'String':
  44. const dataType = prop.mysql && prop.mysql.dataType || '';
  45. if (dataType.toUpperCase() === 'BINARY') {
  46. val = val instanceof Buffer ? val.toString('hex') : val;
  47. } else {
  48. val = String(val);
  49. }
  50.  
  51. break;
  52. `
Add Comment
Please, Sign In to add comment