Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const pg = require("pg");
- const dbConfig =
- { user: 'root'
- , database: 'sasdb_blueprint' // Set your database name here
- , password: ''
- , port: 5432
- };
- const pool = new pg.Pool(dbConfig);
- const args = process.argv;
- const searchVal = args[2];
- const callback = (val) => {
- console.log(JSON.stringify(val));
- }
- const execute = (command,callback) => {
- pool.connect(function (err, client, done) {
- if (err) {
- // console.log("Error :",err);
- } else {
- client.query(`set search_path to db39618db;`, function (err, res) { // Need to set search your path here
- client.query(command,function(err,result){
- done();
- if (err) {
- // console.log("Error :",err);
- } else {
- callback(result.rows);
- }
- })
- })
- }
- })
- }
- const getAllTalesQuery = "SELECT table_name FROM information_schema.tables WHERE table_schema='zohocrm_jbossdb' AND table_type='BASE TABLE';"
- const allTablesCallBack = (resp) => {
- console.log(`Search results for ${searchVal}`);
- resp.forEach(table => {
- let tableQry = `SELECT * from ${table.table_name};`;
- let callback = tableVal => {
- tableVal.every(eachRow => {
- let returnVal = true;
- for(let key in eachRow){
- let value = eachRow[key];
- // value = value ? value+"" : "";
- // if(value.indexOf(searchVal) != -1){
- if(value == searchVal) {
- console.log(table.table_name, " : " ,key);
- returnVal = false;
- }
- }
- return returnVal;
- })
- };
- execute(tableQry,callback);
- })
- }
- execute(getAllTalesQuery,allTablesCallBack);
Add Comment
Please, Sign In to add comment