Skip to content

Commit cebc29c

Browse files
committed
removed/commented unneeded console.logs
1 parent 8c840cc commit cebc29c

File tree

2 files changed

+82
-90
lines changed

2 files changed

+82
-90
lines changed

src/pg-import/pgQuery.js

Lines changed: 82 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const dotenv = require('dotenv');
66
const pgQuery = async function(fetchedTables) {
77
//reads the .env config after latest update, allowing us to use new tables if a previous import has run
88
dotenv.config();
9-
9+
const URI = process.env.DB_URI
10+
1011
const tableQuery = `
1112
SELECT table_name,
1213
ordinal_position as position,
@@ -28,18 +29,13 @@ const pgQuery = async function(fetchedTables) {
2829
FROM information_schema.constraint_column_usage
2930
WHERE table_schema not in ('information_schema', 'pg_catalog') AND
3031
table_name not in ('pg_stat_statements')
31-
ORDER BY table_name;`
32-
33-
let tableColumns = {};
34-
35-
//this is not updating!!
36-
const URI = process.env.DB_URI
32+
ORDER BY table_name;`
3733

3834
const pool = new Pool({
3935
connectionString: URI,
4036
ssl: true,
4137
})
42-
console.log('db uri pre pool.connect:', URI)
38+
// console.log('db uri pre pool.connect:', URI)
4339

4440
pool.connect((err, client, done) => {
4541
if (err) return console.log(`Error connecting to db, ${err}`);
@@ -48,92 +44,90 @@ const pgQuery = async function(fetchedTables) {
4844
})
4945

5046
let queryResults = await pool.query(tableQuery)
51-
.then(res => {
52-
console.log("pool: ",pool)
53-
console.log('db URI: ', URI)
54-
console.log('tableQuery: ',res.rows)
55-
tableColumns = res.rows;
56-
return tableColumns;
57-
})
58-
.then(tableColumns => {
59-
return pool.query(constraintQuery)
60-
.then(res => {
61-
// console.log('constraintQuery: ',res.rows)
62-
const result = res.rows;
63-
for(let item of result){
64-
// console.log("tablecolumns: ", tableColumns)
65-
let table = item.table_name;
66-
let col = item.column_name;
67-
for(let column of tableColumns){
68-
// console.log('column: ', column, "col: ", col)
69-
if(column.table_name == table && column.column_name == col){
70-
column.constraint = item.constraint_name;
47+
.then(res => {
48+
// console.log("pool: ",pool)
49+
// console.log('db URI: ', URI)
50+
// console.log('tableQuery: ',res.rows)
51+
const tableColumns = res.rows;
52+
return tableColumns;
53+
})
54+
.then(tableColumns => {
55+
return pool.query(constraintQuery)
56+
.then(res => {
57+
// console.log('constraintQuery: ',res.rows)
58+
const result = res.rows;
59+
for(let item of result){
60+
// console.log("tablecolumns: ", tableColumns)
61+
let table = item.table_name;
62+
let col = item.column_name;
63+
for(let column of tableColumns){
64+
// console.log('column: ', column, "col: ", col)
65+
if(column.table_name == table && column.column_name == col){
66+
column.constraint = item.constraint_name;
67+
}
7168
}
7269
}
73-
}
74-
const tables = {};
75-
let index = -1;
76-
tableColumns.forEach((item) => {
77-
//if table type matches index, do not create new table index
78-
if(!tables[index] || tables[index].type !== item.table_name){
79-
//increment index to move on to new table
80-
index++
81-
tables[index] = {};
82-
tables[index].type = item.table_name;
83-
tables[index].fields = {};
84-
tables[index].fieldIndex = 0;
85-
tables[index].tableID = index.toString();
86-
tables[index].fields = [];
87-
}
88-
tables[index].fieldIndex ++;
89-
90-
// tables[index].fields[position] = {};
91-
const column = {};
92-
column.name = item.column_name;
93-
94-
//assigns column data types from Postgres to match our app's data types
95-
switch(item.data_type){
96-
case "character varying":
97-
column.type = "String";
98-
break;
99-
case "integer":
100-
column.type = "Int";
101-
break;
102-
case "serial":
103-
column.type = "ID";
104-
break;
105-
case "boolean":
106-
column.type = "Boolean"
70+
const tables = {};
71+
let index = -1;
72+
tableColumns.forEach((item) => {
73+
//if table type matches index, do not create new table index
74+
if(!tables[index] || tables[index].type !== item.table_name){
75+
//increment index to move on to new table
76+
index++
77+
tables[index] = {};
78+
tables[index].type = item.table_name;
79+
tables[index].fields = {};
80+
tables[index].fieldIndex = 0;
81+
tables[index].tableID = index.toString();
82+
tables[index].fields = [];
10783
}
108-
column.required = item.is_nullable == "YES" ? true : false;
109-
column.tableNum = index.toString();
110-
column.fieldNum = item.position;
111-
column.defaultValue = item.default_value ? item.default_value : "";
112-
//values that need to be fetched from db
113-
column.primaryKey = false;
114-
column.unique = false;
115-
column.relationSelected = false;
116-
column.relation = {
117-
tableIndex: -1,
118-
fieldIndex: -1,
119-
refType: ''
120-
},
121-
column.queryable = true;
84+
tables[index].fieldIndex ++;
12285

123-
tables[index].fields.push(column)
124-
})
125-
console.log("tables (pgquery): ", tables)
126-
fetchedTables = tables;
127-
return fetchedTables;
128-
// console.log('final table column obj: ', tableColumns)
86+
// tables[index].fields[position] = {};
87+
const column = {};
88+
column.name = item.column_name;
89+
90+
//assigns column data types from Postgres to match our app's data types
91+
switch(item.data_type){
92+
case "character varying":
93+
column.type = "String";
94+
break;
95+
case "integer":
96+
column.type = "Int";
97+
break;
98+
case "serial":
99+
column.type = "ID";
100+
break;
101+
case "boolean":
102+
column.type = "Boolean"
103+
}
104+
column.required = item.is_nullable == "YES" ? true : false;
105+
column.tableNum = index.toString();
106+
column.fieldNum = item.position;
107+
column.defaultValue = item.default_value ? item.default_value : "";
108+
//values that need to be fetched from db
109+
column.primaryKey = false;
110+
column.unique = false;
111+
column.relationSelected = false;
112+
column.relation = {
113+
tableIndex: -1,
114+
fieldIndex: -1,
115+
refType: ''
116+
},
117+
column.queryable = true;
118+
119+
tables[index].fields.push(column)
120+
})
121+
// console.log("tables (pgquery): ", tables)
122+
fetchedTables = tables;
123+
return fetchedTables;
124+
// console.log('final table column obj: ', tableColumns)
125+
})
126+
129127
})
130-
131-
})
132-
.catch(err => console.error('Error is: ', err))
133-
let results = queryResults;
134-
return results;
128+
.catch(err => console.error('Error is: ', err))
129+
return queryResults;
135130
}
136131

137132
module.exports = pgQuery;
138133

139-
// console.log("tableRes: ", tableRes)

src/state/store.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ function reducer(state, action) {
148148
}
149149
//Updates the endpoint as input by the user.
150150
case "ADD_APOLLO_SERVER_URI":
151-
// let newStr = uriInputString;
152-
// uriInputString = '';
153151
return {
154152
...state,
155153
apolloServerURI: action.payload,

0 commit comments

Comments
 (0)