{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/14468","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/14468/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/14468/comments","events_url":"https://api.github.com/repos/golang/go/issues/14468/events","html_url":"https://github.com/golang/go/issues/14468","id":135486498,"number":14468,"title":"database/sql: common interface for query functions in sql.DB and sql.Tx","user":{"login":"KilledKenny","id":1319915,"avatar_url":"https://avatars.githubusercontent.com/u/1319915?v=3","gravatar_id":"","url":"https://api.github.com/users/KilledKenny","html_url":"https://github.com/KilledKenny","followers_url":"https://api.github.com/users/KilledKenny/followers","following_url":"https://api.github.com/users/KilledKenny/following{/other_user}","gists_url":"https://api.github.com/users/KilledKenny/gists{/gist_id}","starred_url":"https://api.github.com/users/KilledKenny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KilledKenny/subscriptions","organizations_url":"https://api.github.com/users/KilledKenny/orgs","repos_url":"https://api.github.com/users/KilledKenny/repos","events_url":"https://api.github.com/users/KilledKenny/events{/privacy}","received_events_url":"https://api.github.com/users/KilledKenny/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"kardianos","id":755121,"avatar_url":"https://avatars.githubusercontent.com/u/755121?v=3","gravatar_id":"","url":"https://api.github.com/users/kardianos","html_url":"https://github.com/kardianos","followers_url":"https://api.github.com/users/kardianos/followers","following_url":"https://api.github.com/users/kardianos/following{/other_user}","gists_url":"https://api.github.com/users/kardianos/gists{/gist_id}","starred_url":"https://api.github.com/users/kardianos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kardianos/subscriptions","organizations_url":"https://api.github.com/users/kardianos/orgs","repos_url":"https://api.github.com/users/kardianos/repos","events_url":"https://api.github.com/users/kardianos/events{/privacy}","received_events_url":"https://api.github.com/users/kardianos/received_events","type":"User","site_admin":false},"assignees":[{"login":"kardianos","id":755121,"avatar_url":"https://avatars.githubusercontent.com/u/755121?v=3","gravatar_id":"","url":"https://api.github.com/users/kardianos","html_url":"https://github.com/kardianos","followers_url":"https://api.github.com/users/kardianos/followers","following_url":"https://api.github.com/users/kardianos/following{/other_user}","gists_url":"https://api.github.com/users/kardianos/gists{/gist_id}","starred_url":"https://api.github.com/users/kardianos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kardianos/subscriptions","organizations_url":"https://api.github.com/users/kardianos/orgs","repos_url":"https://api.github.com/users/kardianos/repos","events_url":"https://api.github.com/users/kardianos/events{/privacy}","received_events_url":"https://api.github.com/users/kardianos/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/6","html_url":"https://github.com/golang/go/milestones/Unplanned","labels_url":"https://api.github.com/repos/golang/go/milestones/6/labels","id":1055141,"number":6,"title":"Unplanned","description":"No plan to fix in any specific release.\r\n","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars.githubusercontent.com/u/104030?v=3","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":1212,"closed_issues":591,"state":"open","created_at":"2015-04-06T20:47:19Z","updated_at":"2016-11-28T18:56:17Z","due_on":"2099-12-31T05:00:00Z","closed_at":null},"comments":6,"created_at":"2016-02-22T17:35:55Z","updated_at":"2016-11-28T18:57:20Z","closed_at":null,"body":"Hi,\n\nI'm proposing a interface that implements all functions in `sql.DB` and `sql.Tx` that takes a `query string` as one of its arguments. This could be useful when implementing \"dumb\" functions that retrieves information but in itself dose not need to be prepared however might be used to verify whether to commit or rollback.\n\nThe interface I'm proposing is: (The name can of course be changed)\n\n``` go\ntype QueryAble interface {\n    Exec(query string, args ...interface{}) (sql.Result, error)\n    Prepare(query string) (*sql.Stmt, error)\n    Query(query string, args ...interface{}) (*sql.Rows, error)\n    QueryRow(query string, args ...interface{}) *sql.Row\n}\n```\n\nThis is an example function `Get` that can be used with or without transactions.\n\n``` go\nfunc Get (q Queryable)(int){\n    var test int\n    res , _ := q.Query(\"SELECT COUNT(*) FROM table;\")\n    res.Next()\n    res.Scan(&test)\n    res.Close()\n    return test\n}\n\nfunc GetExample(db *sql.DB){\n\n    //When you just want to retrieve the information, no need for a transaction\n    fmt.Printf(\"Current len of Table %d\\n\", Get(db))\n\n    //Make a change\n    tx, _ :=db.Begin()\n    // Add data to table\n    if  Get(tx) > 2 {\n        fmt.Printf(\"Table to large: %d robacking to: %d \\n\", Get(tx) , Get(db))\n        tx.Rollback()\n    } else {\n        fmt.Printf(\"Table update new len %d\\n\", Get(tx))\n        tx.Commit()\n    }\n}\n```\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/263360088","html_url":"https://github.com/golang/go/issues/14468#issuecomment-263360088","issue_url":"https://api.github.com/repos/golang/go/issues/14468","id":263360088,"user":{"login":"kardianos","id":755121,"avatar_url":"https://avatars.githubusercontent.com/u/755121?v=3","gravatar_id":"","url":"https://api.github.com/users/kardianos","html_url":"https://github.com/kardianos","followers_url":"https://api.github.com/users/kardianos/followers","following_url":"https://api.github.com/users/kardianos/following{/other_user}","gists_url":"https://api.github.com/users/kardianos/gists{/gist_id}","starred_url":"https://api.github.com/users/kardianos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kardianos/subscriptions","organizations_url":"https://api.github.com/users/kardianos/orgs","repos_url":"https://api.github.com/users/kardianos/repos","events_url":"https://api.github.com/users/kardianos/events{/privacy}","received_events_url":"https://api.github.com/users/kardianos/received_events","type":"User","site_admin":false},"created_at":"2016-11-28T18:57:20Z","updated_at":"2016-11-28T18:57:20Z","body":"The API for rollback / savepoint may also factor into this conversation: #7898."}}
{"actor":{"display_login":"kardianos"}}