Skip to content

Commit

Permalink
adds sql code for specific role query w dept join
Browse files Browse the repository at this point in the history
  • Loading branch information
JDR8888 committed Mar 15, 2023
1 parent cef687b commit 2708208
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.env
notes.txt
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ demo of the project:
# Installation
N/A
# Usage
N/A
Download/clone the repo. npm install the packages/libraries needed, open up your terminal inside the repo, and enter 'node index.js'
# Credits
[![forthebadge](https://forthebadge.com/images/badges/uses-badges.svg)](https://forthebadge.com)
inquire.js , node.js, console table, node-mysql2
Expand Down
7 changes: 7 additions & 0 deletions db/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- query for getting all job roles with department name shown through a join
select
role.title as job_title,
department.name as department
from role
join department on
role.department_id = department.id;
21 changes: 16 additions & 5 deletions db/seeds.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
-- insert into department (name)
-- values ("logistics"),
-- ("human resources"),
-- ("sales"),
-- ("accounting");
insert into department (name)
values ("logistics"),
("human resources"),
("sales"),
("accounting");

insert into role
(title,salary,department_id)
values ("swiper", 69420, 1),
("assistant to the regional manager", 43100, 3),
("pencil pusher", 175000, 2);

insert into employee
(first_name, last_name, role_id, manager_id)
values
("baba", "booey", 1, 2),
("dwight","schrute", 2, 2);

insert into employee
(first_name, last_name, role_id)
values
("slithy", "tove", 3);
Empty file added dbFunctions.js
Empty file.
50 changes: 24 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,59 @@ connection.connect((err) => {
console.log('Connected!');
});

// define the set of primary options to display to the user while navigating the app in the terminal.
const options = [
{
value: "view all departments",
num: "1"
value: "view all departments",
},
{
value: "view all roles",
num: "2"
},
{
value: "view all employees",
num: "3"
},
{
value: "add a department",
num: "4"
},
{
value: "add a role",
num: "5"
},
{
value: "add an employee",
num: "6"
},
{
value: "update an employee role",
num: "7"
}
];

inquirer.prompt(
inquirer.prompt(
{
type:'list',
message: "omg what do you want",
choices: options,
name: "desire"
},
).then((answers) => {
// let val = answers.desire.num;
console.log(`you chose ${answers.value}`);
// console.log(answers.desire.num);
const table = 'department';
// connection.query(
// `SELECT * FROM ${table}`, function(err,results,fields) {
// console.table(results);
// }
// );
let table;
// let val = answers;
switch (answers.desire) {
case "view all departments":
table = 'department';
break;
case "view all roles":
table = 'role';
break;
case "view all employees":
table = 'employee';
break;
}
// console.log(choices[0]);
// const table = 'department';
connection.query(
`SELECT * FROM ${table}`, function(err,results,fields) {
console.log(`\x1b[35m here is your results \x1b[0m`)
console.table(results);
}
);
});


// connection.query(
// 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
// ['Page', 45],
// function(err, results) {
// console.log(results);
// }
// );
23 changes: 22 additions & 1 deletion notes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
view all departments,
view all roles,
mysql> source query.sql
+-----------------------------------+-----------------+
| job_title | department |
+-----------------------------------+-----------------+
| swiper | logistics |
| assistant to the regional manager | sales |
| pencil pusher | human resources |
+----------------------------------
view all employees,
add a department,
add a role,
add an employee,
and update an employee role
and update an employee role


try to add some additional functionality to your application, such as the ability to do the following:

Update employee managers.

View employees by manager.

View employees by department.

Delete departments, roles, and employees.

View the total utilized budget of a department—in other words, the combined salaries of all employees in that department.

0 comments on commit 2708208

Please sign in to comment.