{"action":"created","issue":{"url":"https://api.github.com/repos/mjhea0/node-postgres-promises/issues/5","repository_url":"https://api.github.com/repos/mjhea0/node-postgres-promises","labels_url":"https://api.github.com/repos/mjhea0/node-postgres-promises/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/mjhea0/node-postgres-promises/issues/5/comments","events_url":"https://api.github.com/repos/mjhea0/node-postgres-promises/issues/5/events","html_url":"https://github.com/mjhea0/node-postgres-promises/issues/5","id":141738921,"number":5,"title":"Uses two identical queries","user":{"login":"Delphinator","id":371980,"avatar_url":"https://avatars.githubusercontent.com/u/371980?v=3","gravatar_id":"","url":"https://api.github.com/users/Delphinator","html_url":"https://github.com/Delphinator","followers_url":"https://api.github.com/users/Delphinator/followers","following_url":"https://api.github.com/users/Delphinator/following{/other_user}","gists_url":"https://api.github.com/users/Delphinator/gists{/gist_id}","starred_url":"https://api.github.com/users/Delphinator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Delphinator/subscriptions","organizations_url":"https://api.github.com/users/Delphinator/orgs","repos_url":"https://api.github.com/users/Delphinator/repos","events_url":"https://api.github.com/users/Delphinator/events{/privacy}","received_events_url":"https://api.github.com/users/Delphinator/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-03-18T00:00:45Z","updated_at":"2016-03-22T21:21:01Z","closed_at":"2016-03-22T21:21:01Z","body":"These two queries are exactly the same and both get executed for a single request:\r\n- [`get SINGLE puppy`](https://github.com/mjhea0/node-postgres-promises/blob/master/routes/index.js#L36-L37)\r\n- [`checkID`](https://github.com/mjhea0/node-postgres-promises/blob/master/routes/index.js#L109-L110)\r\n\r\nI know it makes the code a bit shorter and arguably nicer, but this seems pretty wasteful and bad practice in any real-world-code.\r\n\r\nIt also introduces a race condition, because those two queries are not using a transaction: Take to requests `DELETE /api/puppies/1` (referred to as `DEL`) and `GET /api/puppies/1` (referred to as `GET` and assume the following chain of events:\r\n- `DEL` executes `checkID`, finds puppy `1`\r\n- `GET` executes `checkID`, finds puppy `1`\r\n- `DEL` deletes puppy `1`\r\n- `GET` will not find puppy `1` and return 500\r\n\r\nThat's not terrible (\"just\" a wrong error code), but also far from great. The `GET` request above can also be exchanged with an `PUT` request."},"comment":{"url":"https://api.github.com/repos/mjhea0/node-postgres-promises/issues/comments/200035297","html_url":"https://github.com/mjhea0/node-postgres-promises/issues/5#issuecomment-200035297","issue_url":"https://api.github.com/repos/mjhea0/node-postgres-promises/issues/5","id":200035297,"user":{"login":"mjhea0","id":2018167,"avatar_url":"https://avatars.githubusercontent.com/u/2018167?v=3","gravatar_id":"","url":"https://api.github.com/users/mjhea0","html_url":"https://github.com/mjhea0","followers_url":"https://api.github.com/users/mjhea0/followers","following_url":"https://api.github.com/users/mjhea0/following{/other_user}","gists_url":"https://api.github.com/users/mjhea0/gists{/gist_id}","starred_url":"https://api.github.com/users/mjhea0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjhea0/subscriptions","organizations_url":"https://api.github.com/users/mjhea0/orgs","repos_url":"https://api.github.com/users/mjhea0/repos","events_url":"https://api.github.com/users/mjhea0/events{/privacy}","received_events_url":"https://api.github.com/users/mjhea0/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T21:21:01Z","updated_at":"2016-03-22T21:21:01Z","body":"updated to pass all errors to the express error handler"}}