Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. var connection = require("./connection.js");
  2.  
  3. // Object Relational Mapper (ORM)
  4.  
  5. // The ?? signs are for swapping out table or column names
  6. // The ? signs are for swapping out other values
  7. // These help avoid SQL injection
  8. // https://en.wikipedia.org/wiki/SQL_injection
  9.  
  10. var orm = {
  11. selectAll: function(tableInput, cb) {
  12. var queryString = "SELECT * FROM ??";
  13. connection.query(queryString, tableInput, function(err, result) {
  14. if (err) throw err;
  15. console.log(result);
  16. cb(result);
  17. });
  18. },
  19. insertOne: function(tableInput, columnInput, valueInput, cb) {
  20. var queryString = "INSERT INTO ?? (??) VALUES(?)";
  21. connection.query(queryString, [tableInput, columnInput, valueInput], function(err, result) {
  22. if (err) throw err;
  23. console.log(result);
  24. cb(result);
  25. });
  26. },
  27. updateOne: function(tableInput, columnInput, valueInput, conditionCol, conditionVal, cb) {
  28. var queryString = "UPDATE ?? SET ?? = ? WHERE ?? = ?";
  29. connection.query(queryString, [tableInput, columnInput, valueInput, conditionCol, conditionVal], function(err, result) {
  30. if (err) throw err;
  31. console.log(result);
  32. cb(result);
  33. });
  34. }
  35. }
  36.  
  37. module.exports = orm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement