Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. const mysql = require('mysql');
  2.  
  3. const connection = mysql.createConnection({
  4. host:'localhost',
  5. user: 'root',
  6. password:'qweasdzxc',
  7. database: 'testdb',
  8. });
  9.  
  10. const tableName = 'customers';
  11.  
  12. connection.connect();
  13.  
  14. /*==========METHODS==========*/
  15.  
  16. //TODO
  17. const config = (function (){
  18. let from;
  19. let where,orderBy;
  20. });
  21.  
  22. const getLimitObjects = function(table, number){
  23. const sqlText = `SELECT * FROM ${table} LIMIT ${number}`;
  24. connection.query(sqlText,(err,result)=>{
  25. if(err){
  26. throw err;
  27. }
  28. console.log(result);
  29. })
  30. };
  31.  
  32. const getAllObjects = function(table,config){
  33. const sqlText = `SELECT * FROM ${table}`;
  34. connection.query(sqlText,(err,result)=>{
  35. if(err){
  36. throw err;
  37. }
  38. console.log(result);
  39. })
  40. };
  41.  
  42. const dropTable = function(table){
  43. const sqText = `DROP TABLE ${table}`;
  44. connection.query(sql,(err,res)=>{
  45. if(err){
  46. throw err;
  47. }
  48. console.log(`Table ${table} was deleted`);
  49. });
  50. };
  51.  
  52. const updateTable = function(table,config){
  53. const sqlText = `UPDATE ${table} SET address = 'Canyon 123' WHERE address = 'Valley 345'`; //config here;
  54. //TODO
  55. connection.query(sqlText,(err,res)=>{
  56. if(err){
  57. throw err;
  58. }
  59. console.log(`${res.affectedRows} records updated`);
  60. });
  61. };
  62.  
  63.  
  64. /*==========TESTING==========*/
  65.  
  66. getLimitObjects(tableName,3);
  67. updateTable(tableName,null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement