Guest User

Untitled

a guest
Jan 31st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. "use strict";
  2.  
  3. const pg = require("pg");
  4.  
  5. const dbConfig =
  6. { user: 'root'
  7. , database: 'sasdb_blueprint' // Set your database name here
  8. , password: ''
  9. , port: 5432
  10. };
  11.  
  12. const pool = new pg.Pool(dbConfig);
  13. const args = process.argv;
  14. const searchVal = args[2];
  15.  
  16. const callback = (val) => {
  17. console.log(JSON.stringify(val));
  18. }
  19.  
  20. const execute = (command,callback) => {
  21. pool.connect(function (err, client, done) {
  22. if (err) {
  23. // console.log("Error :",err);
  24. } else {
  25. client.query(`set search_path to db39618db;`, function (err, res) { // Need to set search your path here
  26. client.query(command,function(err,result){
  27. done();
  28. if (err) {
  29. // console.log("Error :",err);
  30. } else {
  31. callback(result.rows);
  32. }
  33. })
  34. })
  35. }
  36. })
  37. }
  38.  
  39. const getAllTalesQuery = "SELECT table_name FROM information_schema.tables WHERE table_schema='zohocrm_jbossdb' AND table_type='BASE TABLE';"
  40.  
  41. const allTablesCallBack = (resp) => {
  42. console.log(`Search results for ${searchVal}`);
  43. resp.forEach(table => {
  44. let tableQry = `SELECT * from ${table.table_name};`;
  45. let callback = tableVal => {
  46. tableVal.every(eachRow => {
  47. let returnVal = true;
  48. for(let key in eachRow){
  49. let value = eachRow[key];
  50. // value = value ? value+"" : "";
  51. // if(value.indexOf(searchVal) != -1){
  52. if(value == searchVal) {
  53. console.log(table.table_name, " : " ,key);
  54. returnVal = false;
  55. }
  56. }
  57. return returnVal;
  58. })
  59. };
  60. execute(tableQry,callback);
  61. })
  62. }
  63.  
  64. execute(getAllTalesQuery,allTablesCallBack);
Add Comment
Please, Sign In to add comment