Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEI 24 AURELIA #126

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 74 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,91 @@
console.log("works!!", process.argv[2]);

const operation = process.argv[2];
const chore = process.argv[3];
let choreStatus = "[ ]";
const pg = require('pg');

const configs = {
user: 'akira',
user: 'aurelialim',
host: '127.0.0.1',
database: 'todo',
port: 5432,
};

const client = new pg.Client(configs);

let queryDoneCallback = (err, result) => {
if (err) {
console.log("query error", err.message);
} else {
console.log("result", result.rows );
}
client.end();
};

let clientConnectionCallback = (err) => {

if( err ){
console.log( "error", err.message );
}
client.connect((error)=> {
if(error){
console.log('ERROR AT CONNECT', error.message)
} else {
if(operation ==="add"){

let text = "INSERT INTO todo (name) VALUES ($1) RETURNING id";
queryText = 'INSERT INTO items (name, done) VALUES ($1, $2) RETURNING name';
values = [chore, choreStatus];
client.query(queryText,values, (err, res) => {
if (err) {
console.log("query error", err.message);
} else {
console.log("result", res.rows);
}
});
} else if (operation ==='show'){
queryText = 'SELECT * FROM items';
client.query(queryText, (err, res) => {
if (err) {
console.log("query error", err.message);
} else {
console.log("here are your tasks", res.rows);
}
});

const values = ["hello"];
} else if(operation ==="done"){
let id = parseInt(chore);

client.query(text, values, queryDoneCallback);
};
queryText = `UPDATE items SET done='[X]', doneAt= NOW() WHERE id =${id} RETURNING name, doneAt,timeTaken`;
client.query(queryText, (err, res) => {
if (err) {
console.log("query error", err.message);
} else {
console.log("done[X]", res.rows);
}
});

} else if (operation === 'stats' && chore === "complete-time"){
queryText = 'SELECT AVG(doneAt-createdAt) FROM items';
client.query(queryText, (err, res) => {
if (err) {
console.log("query error", err.message);
} else {
console.log(res.rows);
}
})
} else if (operation === 'stats' && chore === "add-time"){
queryText = "SELECT COUNT(id), DATE_TRUNC('day',createdAt) FROM items GROUP BY DATE_TRUNC('day',createdAt)"
client.query(queryText, (err, res) => {
if (err) {
console.log("query error", err.message);
} else {
let listobj = res.rows;
let counter =0;
for(i=0; i<listobj.length; i++){
counter += listobj[i].count
let average = counter/listobj.length;
console.log("The average added per day is", average)
}

client.connect(clientConnectionCallback);
}
})
} else if(operation === 'stats' && chore === "best-worst") {
queryText ="select name, EXTRACT(epoch FROM doneAt-createdAt) AS timeTaken FROM items WHERE doneAt IS NOT NULL ORDER BY timeTaken ASC";
client.query(queryText, (err, res) => {
if(err){
console.log("query error", err.message);
} else {
console.log(res.rows);
}
})
}
}
})
1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/buffer-writer/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions node_modules/buffer-writer/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions node_modules/buffer-writer/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions node_modules/buffer-writer/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions node_modules/buffer-writer/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/buffer-writer/test/mocha.opts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading