Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const Pool = require('pg').Pool
  2. const pool = new Pool({
  3. user: 'postgres',
  4. host: 'localhost',
  5. database: 'api',
  6. password: 'xxxxx',
  7. port: 5432,
  8. })
  9.  
  10. const getSandwich = (request, response) => {
  11. pool.query('SELECT * FROM fluffy.sandwiches ORDER BY sandwich_id ASC', (error, results) => {
  12. if (error) {
  13. throw error
  14. }
  15. response.status(200).json(results.rows)
  16. })
  17. }
  18.  
  19. const getSandwichById = (request, response) => {
  20. const sandwich_id = parseInt(request.params.sandwich_id)
  21.  
  22. pool.query('SELECT * FROM fluffy.sandwiches WHERE sandwich_id = $1', [sandwich_id], (error, results) => {
  23. if (error) {
  24. throw error
  25. }
  26. response.status(200).json(results.rows)
  27. })
  28. }
  29.  
  30. module.exports = {
  31. getSandwich,
  32. getSandwichById
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement