{"action":"created","issue":{"url":"https://api.github.com/repos/go-pg/pg/issues/140","repository_url":"https://api.github.com/repos/go-pg/pg","labels_url":"https://api.github.com/repos/go-pg/pg/issues/140/labels{/name}","comments_url":"https://api.github.com/repos/go-pg/pg/issues/140/comments","events_url":"https://api.github.com/repos/go-pg/pg/issues/140/events","html_url":"https://github.com/go-pg/pg/issues/140","id":143133280,"number":140,"title":"Document how RunInTransaction works","user":{"login":"viblo","id":1195272,"avatar_url":"https://avatars.githubusercontent.com/u/1195272?v=3","gravatar_id":"","url":"https://api.github.com/users/viblo","html_url":"https://github.com/viblo","followers_url":"https://api.github.com/users/viblo/followers","following_url":"https://api.github.com/users/viblo/following{/other_user}","gists_url":"https://api.github.com/users/viblo/gists{/gist_id}","starred_url":"https://api.github.com/users/viblo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viblo/subscriptions","organizations_url":"https://api.github.com/users/viblo/orgs","repos_url":"https://api.github.com/users/viblo/repos","events_url":"https://api.github.com/users/viblo/events{/privacy}","received_events_url":"https://api.github.com/users/viblo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-24T02:52:57Z","updated_at":"2016-03-24T09:07:26Z","closed_at":"2016-03-24T09:06:35Z","body":"We have a small go coding test for potential new employees at my company. From what I can tell a lot of our candidates dont understand how RunInTransaction works. The \"tricky\" part is that you have to actually use the inner `pg.Tx`  to make use of the transaction which many of them doesnt seem to get. Now since this is a coding test it doesnt have any critical effect except it makes it easy for us to filter them out, but I suspect that a lot of normal users of go-pg will make the same mistake.\r\n\r\nWhat Ive seen people do is this: \r\n```\r\ndb.RunInTransaction(func(tx *pg.Tx) error {\r\n\tdb.Exec(\"insert into users (a) values(1)\")\r\n\ttx.Rollback()\r\n\treturn nil\r\n})\r\n```\r\n\r\nInstead you should of course do it this way if you want the insert to be rollbacked:\r\n```\r\ndb.RunInTransaction(func(tx *pg.Tx) error {\r\n\ttx.Exec(\"insert into users (a) values(1)\")\r\n\ttx.Rollback()\r\n\treturn nil\r\n})\r\n```\r\n\r\nMaybe you can add an example / clarify the documentation of this function? I think that can save a lot of tricky debugging for unexperienced users of this library."},"comment":{"url":"https://api.github.com/repos/go-pg/pg/issues/comments/200747138","html_url":"https://github.com/go-pg/pg/issues/140#issuecomment-200747138","issue_url":"https://api.github.com/repos/go-pg/pg/issues/140","id":200747138,"user":{"login":"vmihailenco","id":290976,"avatar_url":"https://avatars.githubusercontent.com/u/290976?v=3","gravatar_id":"","url":"https://api.github.com/users/vmihailenco","html_url":"https://github.com/vmihailenco","followers_url":"https://api.github.com/users/vmihailenco/followers","following_url":"https://api.github.com/users/vmihailenco/following{/other_user}","gists_url":"https://api.github.com/users/vmihailenco/gists{/gist_id}","starred_url":"https://api.github.com/users/vmihailenco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmihailenco/subscriptions","organizations_url":"https://api.github.com/users/vmihailenco/orgs","repos_url":"https://api.github.com/users/vmihailenco/repos","events_url":"https://api.github.com/users/vmihailenco/events{/privacy}","received_events_url":"https://api.github.com/users/vmihailenco/received_events","type":"User","site_admin":false},"created_at":"2016-03-24T09:07:26Z","updated_at":"2016-03-24T09:07:26Z","body":"Thanks for feedback, added https://godoc.org/gopkg.in/pg.v4#example-DB-RunInTransaction"}}