const promise = require('bluebird');
const config = require('./_config');

const options = {
  promiseLib: promise
};

const pgp = require('pg-promise')(options);
const connectionString = config.selectENV(process.env.NODE_ENV);
const db = pgp(connectionString);

const getAllTodos = () => {
  return db.any('select * from todos')
};

const createTodo = (attributes) => {
  const sql = 'insert into todos(description, due) values($1, $2)'

  const variables = [
    attributes.description,
    attributes.due
  ]
  return db.none(sql, variables)
};

const updateTodo = (id, attributes) => {
  attributes.id = parseInt(id)
  const sql = 'update todos set description = $1, status = $2, due = $3 WHERE id = $4'

  const variables = [
    attributes.description,
    attributes.status,
    attributes.due,
    attributes.id
  ]
  return db.none(sql, variables)
};

const deleteTodo = (id) => {
  objId = parseInt(id)
  return db.none('delete from todos where id = $1', [objId])
};

module.exports = {
  getAllTodos,
  createTodo,
  updateTodo,
  deleteTodo
};

@@ -323,24 +323,115 @@
 todos')%0A%7D;%0A%0A
+const getOneTodo = (id) =%3E %7B%0A  return db.one('select * from todos where id = $1', %5Bid%5D)%0A%7D%0A%0A
 const create
@@ -455,16 +455,16 @@
 s) =%3E %7B%0A
-
   const 
@@ -521,16 +521,79 @@
 $1, $2)'
+%0A  const findsql = 'select * from todos where description = $1'
 %0A%0A  cons
@@ -655,24 +655,50 @@
 tes.due%0A  %5D%0A
+  db.none(sql, variables)%0A
   return db.
@@ -689,37 +689,40 @@
 es)%0A  return db.
-n
 one(
+find
 sql, variables)%0A
@@ -850,29 +850,16 @@
  $1,
- status = $2,
  due = $
 3 WH
@@ -858,9 +858,9 @@
  = $
-3
+2
  WHE
@@ -872,9 +872,9 @@
  = $
-4
+3
 '%0A%0A 
@@ -926,31 +926,8 @@
 on,%0A
-    attributes.status,%0A
     
@@ -1065,20 +1065,22 @@
 turn db.
-none
+result
 ('delete
@@ -1182,16 +1182,16 @@
 teTodo,%0A
-
   delete
@@ -1194,12 +1194,26 @@
 leteTodo
+,%0A  getOneTodo
 %0A%7D;%0A

Add query to get one element