Skip to content
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
98 changes: 95 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,96 @@
####### NODE
notes.md
notes3.md

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

####### RAILS

*.rbc
capybara-*.html
.rspec
/log
/tmp
/db/*.sqlite3
/db/*.sqlite3-journal
/public/system
/coverage/
/spec/tmp
**.orig
rerun.txt
pickle-email-*.html

# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/secrets.yml

## Environment normalisation:
/.bundle
/vendor/bundle

# these should all be checked in to normalise the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# if using bower-rails ignore default bower_components path bower.json files
/vendor/assets/bower_components
*.bowerrc
bower.json

# Ignore pow environment settings
.powenv

.DS_Store
.svn
*~
.*.swp
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

####### OSX

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
36 changes: 0 additions & 36 deletions index.js

This file was deleted.

119 changes: 119 additions & 0 deletions package-lock.json

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

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "cli-todo-sql",
"version": "1.0.0",
"description": "![https://i.giphy.com/media/26ufnwz3wDUli7GU0/giphy.webp](https://i.giphy.com/media/26ufnwz3wDUli7GU0/giphy.webp)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Rachelik/cli-todo-sql.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Rachelik/cli-todo-sql/issues"
},
"homepage": "https://github.com/Rachelik/cli-todo-sql#readme",
"dependencies": {
"pg": "^8.0.2"
}
}
71 changes: 71 additions & 0 deletions todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
console.log("works!!", process.argv[2]);

const pg = require('pg');

const configs = {
user: 'rachelik',
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 );
}

const actToDo = process.argv[2].toLowerCase();

if (actToDo === "show") {
//to show all the list
let showItems = "SELECT * FROM items ORDER BY id ASC";
client.query(showItems, queryDoneCallback);

} else if (actToDo === "add") {
//to add item to the list
const taskDescription = process.argv[3];
const createdDate = new Date();
const updatedDate = null;

let addItems = "INSERT INTO items (task, created_at, update_at) VALUES ($1, $2, $3) RETURNING id";
const values = [taskDescription, createdDate, updatedDate];

client.query(addItems, values, queryDoneCallback);
} else if (actToDo === "done") {

//the id of the task that was done to be marked done.
const markDone = "X";
const idToMark = process.argv[3];
const updatedDate = new Date();

let updateStatus = "UPDATE items SET status=$1, update_at=$2, complete_time=age($2, created_at) WHERE id=$3";

const values = [markDone, updatedDate, idToMark];

client.query(updateStatus, values, queryDoneCallback);
} else if (actToDo === "delete") {
const idRowToDelete = process.argv[3];

let deleteRow = "DELETE FROM items WHERE id = $1";
const values = [idRowToDelete];

client.query(deleteRow, values, queryDoneCallback);
} else if (actToDo === "stats") {

let avgCompleteTime = "SELECT AVG(complete_time) FROM items";
client.query(avgCompleteTime, queryDoneCallback);
}
};

client.connect(clientConnectionCallback);