Guest User

Untitled

a guest
Nov 15th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. module.exports = function (query) {
  2. const { Client } = require ('pg')
  3.  
  4. const connection = {
  5. user: 'postgres',
  6. host: 'localhost',
  7. database : 'hoteltest',
  8. password: '1234',
  9. port: 5432
  10. }
  11.  
  12. const client = new Client(connection)
  13.  
  14. var datos;
  15.  
  16. client.connect()
  17. client.query(query)
  18. .then (response => {
  19. datos = response.rows
  20. console.log(datos)
  21. return datos
  22. client.end()
  23. })
  24. .catch(err => {
  25. console.log(err)
  26. client.end()
  27. })
  28. }
  29.  
  30. import data from './pg/index.js'
  31.  
  32. var pgdata;
  33. pgdata = data('SELECT * FROM usuarios')
  34.  
  35. console.log(pgdata)
Add Comment
Please, Sign In to add comment