Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. const pg = require('pg');
  2.  
  3. const config = {
  4. host: 'serverzpi.postgres.database.azure.com',
  5. // Do not hard code your username and password.
  6. // Consider using Node environment variables.
  7. user: 'ZpiAdmin@serverzpi',
  8. password: 'Zpi?kam1lNOWAK',
  9. database: 'savingapp',
  10. port: 5432,
  11. ssl: true
  12. };
  13.  
  14. const client = new pg.Client(config);
  15.  
  16. client.connect(err => {
  17. if (err){
  18. console.log(err)
  19. }
  20. else {
  21. queryDb();
  22. }
  23. });
  24.  
  25. function queryDb(){
  26. console.log('Jestesmy w DB');
  27. const query = 'SELECT * FROM \"Tester\"';
  28. client.query(query)
  29. .then(res => {
  30. const rows = res.rows;
  31.  
  32. rows.map(row => {
  33. console.log(`Read: ${JSON.stringify(row)}`);
  34. });
  35.  
  36. process.exit();
  37. })
  38. .catch(err => {
  39. console.log(err);
  40. });
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement