Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. var mysql = require("mysql"),
  2. namer = require('color-namer'),
  3. async = require('async');
  4. var connection = mysql.createConnection({
  5. multipleStatements: true,
  6. host : 'localhost',
  7. user : 'root',
  8. password : 'root',
  9. database : 'xxxx'});
  10. connection.connect();
  11.  
  12.  
  13.  
  14.  
  15. connection.query(
  16. `SELECT color from sg_fashion_colors limit 10`,
  17. function(err, results, fields) {
  18. results.forEach(function(elem){
  19.  
  20. var currentHex = elem['color'],
  21. currentColor = namer(currentHex);
  22. console.log(currentHex);
  23. connection.query(
  24. `INSERT INTO name_color_pat_test (hex, basic) VALUES (?,?);`,
  25. [currentHex,currentColor['basic'][0]['name']] ,
  26. function(err,data){
  27. console.log("insert");
  28. }
  29. );
  30. });
  31. }
  32. );
  33.  
  34. color
  35. insert
  36. color
  37. insert
  38.  
  39. color
  40. color
  41. insert
  42. insert
  43.  
  44. connection.query(
  45. `SELECT color from sg_fashion_colors limit 10`,
  46. function(err, results, fields) {
  47. async.eachSeries(results, function (elem, seriesCallback) {
  48. var currentHex = elem['color'],
  49. currentColor = namer(currentHex);
  50. console.log(currentHex);
  51. connection.query( `INSERT INTO name_color_pat_test (hex, basic) VALUES (?,?);`, // insert the SKU inside a database with their primary color
  52. [currentHex,currentColor['basic'][0]['name']] ,
  53. function(err, results, fields) {
  54. if (err) throw err;
  55. console.log("insert");
  56. seriesCallback(null);
  57. });
  58. }, function(responsetoendofloop){
  59. console.log("everything has run");
  60. });
  61. }
  62. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement