Guest User

Untitled

a guest
Jan 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. const tunnel = require('tunnel-ssh');
  2. import knexLib = require('knex');
  3.  
  4. async function main() {
  5. const sshUserName = 'SSH_USER_NAME';
  6. const sshPassword = 'SSH_PASSWORD';
  7.  
  8. let sshConfig = {
  9. host: 'SSH_HOST_ADDRESS',
  10. port: SSH_PORT,
  11. username: sshUserName,
  12. password: sshPassword,
  13. keepaliveInterval: 60000,
  14. keepAlive: true,
  15. dstHost: 'TUNNEL_DEST_HOST_ADDRESS',
  16. dstPort: TUNNEL_DEST_PORT,
  17. localHost: 'localhost',
  18. localPort: 45432
  19. };
  20.  
  21. const tnl = tunnel(sshConfig, async (err: any, server: any) => {
  22. if (err) {
  23. throw err;
  24. }
  25.  
  26. let knex = knexLib({
  27. client: 'postgresql',
  28. connection: {
  29. database: 'DATABASE_NAME',
  30. port: 45432,
  31. user: 'DATABASE_USER',
  32. password: 'DATABASE_PASSWORD'
  33. }
  34. });
  35.  
  36. const rows = await knex.select().from(TABLE_NAME);
  37. console.log(rows);
  38.  
  39. await knex.destroy();
  40.  
  41. tnl.close();
  42. });
  43. }
  44.  
  45. main();
Add Comment
Please, Sign In to add comment