{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/829","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/829/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/829/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/829/events","html_url":"https://github.com/tgriesser/knex/issues/829","id":77183340,"number":829,"title":"Sequential instructions not possible, ie. del, insert, del, insert.","user":{"login":"Hesse","id":335354,"avatar_url":"https://avatars.githubusercontent.com/u/335354?v=3","gravatar_id":"","url":"https://api.github.com/users/Hesse","html_url":"https://github.com/Hesse","followers_url":"https://api.github.com/users/Hesse/followers","following_url":"https://api.github.com/users/Hesse/following{/other_user}","gists_url":"https://api.github.com/users/Hesse/gists{/gist_id}","starred_url":"https://api.github.com/users/Hesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hesse/subscriptions","organizations_url":"https://api.github.com/users/Hesse/orgs","repos_url":"https://api.github.com/users/Hesse/repos","events_url":"https://api.github.com/users/Hesse/events{/privacy}","received_events_url":"https://api.github.com/users/Hesse/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-17T01:56:31Z","updated_at":"2015-05-18T05:45:54Z","closed_at":"2015-05-18T05:45:54Z","body":"Hi, \r\n\r\nI've run into a big problem. I need to be able to delete, then insert, but when I try to do that I always get duplicate key insert errors. \r\n\r\nIf you look at the knex debug output you'll see that all the delete operations are put together and then all the insert operations are put together. This totally voids any sort of sequence control. \r\n\r\nHere's an example:\r\n\r\nvar row, rows, yagga;\r\n\r\nrow = {\r\n  score: 311017,\r\n  user_id: 1042,\r\n  episode_id: 122\r\n};\r\n\r\nrows = [];\r\n\r\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(function() {\r\n  return rows.push(row);\r\n});\r\n\r\nyagga = function(row) {\r\n  console.log(\"trying \" + row);\r\n  return knex(\"episode_scores\").where({\r\n    user_id: row.user_id,\r\n    episode_id: row.episode_id\r\n  }).del().then(function(ret) {\r\n    return knex(\"episode_scores\").insert({\r\n      user_id: row.user_id,\r\n      episode_id: row.episode_id,\r\n      score: row.score\r\n    });\r\n  }).catch(console.error);\r\n};\r\n\r\nrows.map(yagga);\r\n"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/102928043","html_url":"https://github.com/tgriesser/knex/issues/829#issuecomment-102928043","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/829","id":102928043,"user":{"login":"Hesse","id":335354,"avatar_url":"https://avatars.githubusercontent.com/u/335354?v=3","gravatar_id":"","url":"https://api.github.com/users/Hesse","html_url":"https://github.com/Hesse","followers_url":"https://api.github.com/users/Hesse/followers","following_url":"https://api.github.com/users/Hesse/following{/other_user}","gists_url":"https://api.github.com/users/Hesse/gists{/gist_id}","starred_url":"https://api.github.com/users/Hesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hesse/subscriptions","organizations_url":"https://api.github.com/users/Hesse/orgs","repos_url":"https://api.github.com/users/Hesse/repos","events_url":"https://api.github.com/users/Hesse/events{/privacy}","received_events_url":"https://api.github.com/users/Hesse/received_events","type":"User","site_admin":false},"created_at":"2015-05-18T05:45:54Z","updated_at":"2015-05-18T05:45:54Z","body":"Sorry, not really an issue when using transactions. Closing this ticket. \r\n"}}