Advertisement
shakirsamoon

TypeScript to pass JSON object to MySQL

Nov 25th, 2019
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const aaa: any = {
  2.     "patta eka": 4,
  3.     "yo eloo": "dsadd",
  4.     "hmm fatta": "hik"
  5. };
  6.  
  7.     let value = `JSON_OBJECT(`;
  8.  
  9. for (var key in aaa) {
  10.     if (aaa.hasOwnProperty(key)) {
  11.         console.log(key + ": " + aaa[key]);
  12.         value += `"${key}", `;
  13.         if (typeof aaa[key] === "string") {
  14.           value += `"${aaa[key]}",`;
  15.         } else {
  16.           value += `${aaa[key]},`;
  17.         }
  18.     }
  19. }
  20.  
  21. value = value.slice(0, -1);
  22. value += `)`;
  23.  
  24. let _query: string = `CALL testing(${value})`;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement