Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Pool = require('pg').Pool
- const pool = new Pool({
- user: 'postgres',
- host: 'localhost',
- database: 'api',
- password: 'xxxxx',
- port: 5432,
- })
- const getSandwich = (request, response) => {
- pool.query('SELECT * FROM fluffy.sandwiches ORDER BY sandwich_id ASC', (error, results) => {
- if (error) {
- throw error
- }
- response.status(200).json(results.rows)
- })
- }
- const getSandwichById = (request, response) => {
- const sandwich_id = parseInt(request.params.sandwich_id)
- pool.query('SELECT * FROM fluffy.sandwiches WHERE sandwich_id = $1', [sandwich_id], (error, results) => {
- if (error) {
- throw error
- }
- response.status(200).json(results.rows)
- })
- }
- module.exports = {
- getSandwich,
- getSandwichById
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement