Skip to content

Commit f3447dd

Browse files
authored
Merge branch 'dev' into ycbran
2 parents b6a7486 + 5454af4 commit f3447dd

File tree

10 files changed

+108
-143
lines changed

10 files changed

+108
-143
lines changed

.DS_Store

0 Bytes
Binary file not shown.

server/controllers/helperFunctions/universal.helpers.ts

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ const tableNameFormat = async (req: Request, dbDataSource: DataSource) => {
77
const { db_type, username } = req.session;
88
const { tableName } = req.body;
99

10-
// let newTableName = '';
11-
// if (tableName.substring(0, 7) === '.public') {
12-
// newTableName = tableName.slice(7)
13-
// } else {
14-
// newTableName = tableName
15-
// };
16-
1710
let tableNameFormat = '';
1811
switch (db_type) {
1912
case 'oracle':
@@ -194,7 +187,7 @@ export const updateRow: RequestHandler = async (req: Request, _res: Response, ne
194187

195188
await dbDataSource.destroy();
196189
console.log('Database has been disconnected');
197-
return dbUpdatedRow;
190+
return dbUpdatedRow;
198191

199192
} catch (err: unknown) {
200193
console.log('Error occurred in the updatedRow middleware: ', err);
@@ -209,49 +202,25 @@ export const updateRow: RequestHandler = async (req: Request, _res: Response, ne
209202
export const deleteRow: RequestHandler = async (req: Request, _res: Response, next: NextFunction,) => {
210203
const dbDataSource = await dbConnect(req);
211204
const { db_type } = req.session;
212-
const { primaryKey, value, deletedRow } = req.body
205+
const { value } = req.body
213206

214207
try{
215-
// let tableNameDelete = '';
216-
// switch (db_type) {
217-
// case 'oracle':
218-
// tableNameDelete = `"${(username as string).toUpperCase()}"."${tableName}"`;
219-
// break;
220-
// case 'mssql':
221-
// const schemaName: {[SchemaName: string]: string}[] = await dbDataSource.query(`SELECT SCHEMA_NAME() AS SchemaName;`);
222-
// tableNameDelete = `${schemaName[0].SchemaName}.${tableName}`;
223-
// break;
224-
// default:
225-
// tableNameDelete = tableName;
226-
// break;
227-
// };
228-
229208
const tableNameDelete = await Promise.resolve(tableNameFormat(req, dbDataSource));
230209

231-
if (primaryKey){
232-
// Deleting a row that has a PK
233-
await dbDataSource.query(`
234-
DELETE FROM ${tableNameDelete}
235-
WHERE ${db_type === 'oracle' ? `"${primaryKey}"` : primaryKey} = ${db_type === 'oracle' || db_type === 'mysql' ? `'${value}'` : value}
236-
`)
237-
238-
} else {
239-
// Deleting a row that does NOT have a PK
240-
const deleteEntries = Object.entries(deletedRow).filter(([_key, value]) => value !== null);
241-
const deleteKeys = deleteEntries.map(([key, _value]) => key);
242-
const deleteValues = deleteEntries.map(([_key, value]) => value);
243-
244-
let oracleKeyValueString = '';
245-
for (let i = 0; i < deleteKeys.length; i++) {
246-
oracleKeyValueString += `"${deleteKeys[i]}" = '${deleteValues[i]}'${i < deleteKeys.length - 1 ? ' AND ' : ''}`
247-
};
248-
const keyValueString = oracleKeyValueString.replace(/"/g, '');
210+
const deleteEntries = Object.entries(value).filter(([_key, value]) => value !== null);
211+
const deleteKeys = deleteEntries.map(([key, _value]) => key);
212+
const deleteValues = deleteEntries.map(([_key, value]) => value);
249213

250-
await dbDataSource.query(`
251-
DELETE FROM ${tableNameDelete}
252-
WHERE ${db_type === 'oracle' ? oracleKeyValueString : keyValueString }
253-
`)
214+
let oracleKeyValueString = '';
215+
for (let i = 0; i < deleteKeys.length; i++) {
216+
oracleKeyValueString += `"${deleteKeys[i]}" = '${deleteValues[i]}'${i < deleteKeys.length - 1 ? ' AND ' : ''}`
254217
};
218+
const keyValueString = oracleKeyValueString.replace(/"/g, '');
219+
220+
await dbDataSource.query(`
221+
DELETE FROM ${tableNameDelete}
222+
WHERE ${db_type === 'oracle' ? oracleKeyValueString : keyValueString }
223+
`)
255224

256225
dbDataSource.destroy();
257226
console.log('Database has been disconnected');
@@ -279,26 +248,33 @@ export const addNewDbColumn: RequestHandler = async (req: Request, _res: Respons
279248
console.log('tableNameAddColumn: ', tableNameAddColumn)
280249

281250
let keyValueString: string = '';
282-
let repeatingKeyValueString: string = '';
283251
let newColumnString: string = ''
284252

285253
columnData.forEach((el: NewColumn) => {
286-
if (db_type === 'mssql' || db_type === 'oracle') {
287-
repeatingKeyValueString += `ALTER TABLE ${tableNameAddColumn} ADD "${el.name}" ${el.type === 'AUTO_INCREMENT' ? 'INT' : el.type}${el.isPrimary ? ' PRIMARY KEY' : ''}${el.isNullable ? '' : ' NOT NULL'}${el.defaultValue ? ` DEFAULT ${el.defaultValue}` : ''}${el.type === 'AUTO_INCREMENT' ? ' AUTO_INCREMENT' : ''}; `
288-
} else {
254+
if (db_type === 'mssql') {
255+
keyValueString += `ALTER TABLE ${tableNameAddColumn} ADD "${el.name}" ${el.type === 'AUTO_INCREMENT' ? 'INT' : el.type}${el.isPrimary ? ' PRIMARY KEY' : ''}${el.isNullable ? '' : ' NOT NULL'}${el.defaultValue ? ` DEFAULT ${el.defaultValue}` : ''}${el.type === 'AUTO_INCREMENT' ? ' AUTO_INCREMENT' : ''}; `
256+
} else if(db_type === 'oracle') {
257+
let number: string = '';
258+
if (el.type.includes('VARCHAR')) {
259+
const regex = /\((\d+)\)/;
260+
const match = el.type.match(regex)
261+
number = (match as RegExpMatchArray)[1]
262+
}
263+
keyValueString += `ALTER TABLE ${tableNameAddColumn} ADD(${el.name} ${el.type.includes('VARCHAR') ? `VARCHAR2(${+number})` : el.type}${el.isPrimary ? ' PRIMARY KEY' : ''}${el.isNullable ? '' : ' NOT NULL'}${el.defaultValue ? ` DEFAULT ${el.defaultValue}` : ''}${el.type === 'AUTO_INCREMENT' ? ' AUTO_INCREMENT' : ''}))`
264+
} else {
289265
keyValueString += `ADD${db_type === 'postgres' ? ' COLUMN' : '' } ${ db_type === 'mysql' ? `${el.name}` : `"${el.name}"`} ${el.type === 'AUTO_INCREMENT' ? 'INT' : el.type}${el.isPrimary ? ' PRIMARY KEY' : ''}${el.isNullable ? '' : ' NOT NULL'}${el.defaultValue ? ` DEFAULT ${el.defaultValue}` : ''}${el.type === 'AUTO_INCREMENT' ? ' AUTO_INCREMENT' : ''}, `
290266
};
291267
});
292268

293269
if (db_type === 'mssql' || db_type === 'oracle') {
294-
newColumnString = repeatingKeyValueString.slice(0, -1);
270+
newColumnString = keyValueString.slice(0, -1);
295271
} else {
296272
newColumnString = keyValueString.slice(0, -2);
297-
}
273+
};
298274

299-
if (db_type === 'mssql') {
275+
if (db_type === 'mssql' || db_type === 'oracle') {
300276
const addedNewColumn: Promise<unknown> = await dbDataSource.query(`
301-
${repeatingKeyValueString}
277+
${newColumnString}
302278
`);
303279

304280
await dbDataSource.destroy();
@@ -329,26 +305,22 @@ export const addNewDbColumn: RequestHandler = async (req: Request, _res: Respons
329305
export const updateDbColumn: RequestHandler = async (req: Request, _res: Response, next: NextFunction,) => {
330306
const dbDataSource = await dbConnect(req);
331307
const { db_type, username } = req.session;
308+
const { tableName, columnName, schemaData, columnData } = req.body;
332309

333310
try{
334-
const updateColumnData: {[key: string]: string } = req.body;
335-
336-
const schemaName = db_type === 'mssql' ? await dbDataSource.query(`SELECT SCHEMA_NAME() AS SchemaName;`) : '';
337-
338-
const slicedTableName = updateColumnData.tableName.slice(7, updateColumnData.tableName.length + 1);
339-
const tableName: string = db_type === 'oracle' ? `"${(username as string).toUpperCase()}"."${slicedTableName}"` :
340-
db_type === 'mssql' ? `${schemaName[0].SchemaName}.${slicedTableName}` : updateColumnData.tableName;
311+
const tableNameUpdateColumn = await Promise.resolve(tableNameFormat(req, dbDataSource));
312+
console.log('schemaData: ', schemaData)
313+
console.log('columnData: ', columnData)
341314

342-
343-
const updatedColumn: Promise<unknown> = await dbDataSource.query(`
344-
ALTER TABLE ${tableName}
345-
${db_type === 'postgres' || db_type === 'microsoft' ? 'ALTER COLUMN' : 'MODIFY' } "${updateColumnData.columnName}" ${updateColumnData.dataType} ${db_type === 'postgres' ? updateColumnData.constraintName : null} ${updateColumnData.constraintExpression}
346-
`);
315+
// const updatedColumn: Promise<unknown> = await dbDataSource.query(`
316+
// ALTER TABLE ${tableNameUpdateColumn}
317+
// ${db_type === 'postgres' || db_type === 'microsoft' ? 'ALTER COLUMN' : 'MODIFY' } "${columnName}" ${db_type} ${db_type === 'postgres' ? updateColumnData.constraintName : null} ${updateColumnData.constraintExpression}
318+
// `);
347319

348320
dbDataSource.destroy();
349321
console.log('Database has been disconnected');
350-
console.log('addedForeignKey in helper: ', updatedColumn);
351-
return updatedColumn;
322+
// console.log('addedForeignKey in helper: ', updatedColumn);
323+
// return updatedColumn;
352324

353325
} catch (err: unknown) {
354326
console.log('Error occurred in the addedForeignKey middleware: ', err);
@@ -364,13 +336,13 @@ export const deleteColumn: RequestHandler = async (req: Request, _res: Response,
364336
const dbDataSource = await dbConnect(req)
365337
const { db_type } = req.session
366338
const { columnName } = req.body
367-
339+
console.log('we are in the helper functions: ', req.body)
368340
try{
369341
const columnTableNameDelete = await Promise.resolve(tableNameFormat(req, dbDataSource));
370342

371343
const deletedColumn: Promise<unknown> = await dbDataSource.query(`
372344
ALTER TABLE ${columnTableNameDelete}
373-
DROP${db_type !== 'mysql' ? ' COLUMN' : null} ${columnName}
345+
DROP${db_type !== 'mysql' ? ' COLUMN' : ''} ${columnName}
374346
`)
375347

376348
dbDataSource.destroy();

server/controllers/microsoftData.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const microsoftController = {
165165
//-------------DELETE COLUMN------------------------------------------------------------
166166
microsoftDeleteColumn: async (req: Request, res: Response, next: NextFunction) => {
167167
try {
168-
deleteColumn(req, res, next);
168+
await Promise.resolve(deleteColumn(req, res, next));
169169
console.log("microsoftDeleteColumn function has concluded");
170170
return next();
171171
} catch (err: unknown) {

server/controllers/mysqlData.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const mysqlController = {
143143
//----------------DELETE ROW---------------------------------------------------------------
144144
mysqlDeleteRow: async (req: Request, res: Response, next: NextFunction) => {
145145
try {
146-
deleteRow(req, res, next);
146+
await Promise.resolve(deleteRow(req, res, next));
147147
console.log("mysqlDeleteRow function has concluded");
148148
return next();
149149
} catch (err: unknown) {

src/assets/contributors/SH.jpg

73.4 KB
Loading

src/components/Home/Contributors.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import michaelCostello from '../../assets/contributors/michael_costello.jpeg';
2020
import stevenGeiger from '../../assets/contributors/steven_geiger.jpg';
2121
import yufaLi from '../../assets/contributors/yufa_li.jpeg';
2222
import DK from '../../assets/contributors/dk.png';
23+
import SH from '../../assets/contributors/SH.jpg';
2324

2425
//for future contributors: add your profile information to the profileList array as an object formatted as shown below, and it will auto-populate the home page with a new profile card
2526

@@ -176,7 +177,7 @@ const profileList: profileInfo[] = [
176177
githubUrl: 'https://github.com/JosephTejeda',
177178
},
178179
{
179-
imgUrl: AG,
180+
imgUrl: SH,
180181
name: 'Stephen Havig',
181182
title: 'Software Engineer',
182183
linkedInUrl: 'https://www.linkedin.com/in/stephen-havig-199340145/',

src/components/ReactFlow/DataTableNode.tsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import Tippy from '@tippyjs/react';
1111
import 'tippy.js/dist/tippy.css';
1212
import informationIcon from '../../../images/informationSqIcon.png';
1313
import useCredentialsStore from '../../store/credentialsStore';
14-
import { Edge, DataNode, DataStore ,RowsOfData , Data, dbCredentials } from '@/Types';
14+
import { Edge, DataNode, DataStore, RowsOfData, Data, dbCredentials } from '@/Types';
15+
16+
1517

1618
export default function DataTableNode({ data} : {data:Data} ) { //this 'data' is created and passed from createdDataNodes, need DATA, not SCHEMA
1719

@@ -27,7 +29,7 @@ export default function DataTableNode({ data} : {data:Data} ) { //this 'data' i
2729

2830
const infoIconStr: string = "Please strictly follow syntax of your database. Ex) leave blank for auto-generating values, primary key must have value, etc. It may cause an error in updating database if you not strictly follow the syntax."
2931

30-
//split up the table into different parts based on how the data is structured.
32+
//split up the table into different parts based on how the data is structured. fetch
3133
const tableName = tableData[0];
3234
let firstRow : string[] = [];
3335
let restRowsData : RowsOfData[]|[] = [];
@@ -135,26 +137,12 @@ const newDatastore = structuredClone(dataStore);
135137

136138
newDatastore[tableName] = restRowsData;
137139
setDataStore({...newDatastore,[id]:restRowsData});
138-
// setDataStore(restRowData);
139-
140-
141-
if('db_type' in dbCredentials){
142-
const sendDeleteRequest = fetch(`/api/sql/${dbCredentials.db_type as string}/deleteRow`,{
143-
method:'DELETE',
144-
headers:{
145-
'Content-Type':'application/json'
146-
},
147-
body:JSON.stringify({tableName : tableName, primaryKey: PK, value: PK !== null ? value[PK]:null })
148-
})
149-
}
150-
151-
if (PK !== null && value[PK] !== undefined) {
152-
const sendDeleteRequest = fetch(`/api/sql/${dbCredentials.db_type}/deleteRow`, {
140+
await fetch(`/api/sql/${dbCredentials.db_type}/deleteRow`, {
153141
method: 'DELETE',
154142
headers: {
155143
'Content-Type': 'application/json'
156144
},
157-
body: JSON.stringify({ tableName: tableName, primaryKey: PK, value: value[PK] })
145+
body: JSON.stringify({ tableName: tableName, value: value })
158146
})
159147
.then((res) => {
160148
//console.log("deleting row info sent")
@@ -184,6 +172,7 @@ const newDatastore = structuredClone(dataStore);
184172
////////////////////////////////////////////
185173
}
186174

175+
187176

188177
//cannot make handles for data table dynamic since size of each column can vary
189178
//TODO: is there better way to assign handle? more dynamic?

0 commit comments

Comments
 (0)