{"action":"created","issue":{"url":"https://api.github.com/repos/upper/db/issues/149","repository_url":"https://api.github.com/repos/upper/db","labels_url":"https://api.github.com/repos/upper/db/issues/149/labels{/name}","comments_url":"https://api.github.com/repos/upper/db/issues/149/comments","events_url":"https://api.github.com/repos/upper/db/issues/149/events","html_url":"https://github.com/upper/db/issues/149","id":140210350,"number":149,"title":"v2 API review","user":{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/upper/db/labels/v2","name":"v2","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"pkieltyka","id":18831,"avatar_url":"https://avatars.githubusercontent.com/u/18831?v=3","gravatar_id":"","url":"https://api.github.com/users/pkieltyka","html_url":"https://github.com/pkieltyka","followers_url":"https://api.github.com/users/pkieltyka/followers","following_url":"https://api.github.com/users/pkieltyka/following{/other_user}","gists_url":"https://api.github.com/users/pkieltyka/gists{/gist_id}","starred_url":"https://api.github.com/users/pkieltyka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkieltyka/subscriptions","organizations_url":"https://api.github.com/users/pkieltyka/orgs","repos_url":"https://api.github.com/users/pkieltyka/repos","events_url":"https://api.github.com/users/pkieltyka/events{/privacy}","received_events_url":"https://api.github.com/users/pkieltyka/received_events","type":"User","site_admin":false},"milestone":null,"comments":0,"created_at":"2016-03-11T15:20:12Z","updated_at":"2016-04-02T21:41:11Z","closed_at":null,"body":"Let's do a throughout review of v2's API and let's change everything that needs to be changed and remove any bloat or non essential feature in order to have a slimmed down version of `db`.\r\n\r\nDatabase, Collection and Result methods are all defined here:\r\n\r\nhttps://github.com/upper/db/blob/v2/db.go\r\n\r\nA few initial thoughts and awkward cases that I think we need to solve:\r\n\r\n* `Collection.Append()` This does not actually *adds rows to the end of the table*, we need a different name, `Collection.Insert()`?. See https://github.com/upper/db/pull/160\r\n* `Collection.Append` returns an `interface{}` with an ID that the user has to cast to the appropriate ID type. We can't return an integer because not every ID is an integer. I think `Append() (interface{}, error)` should be `Append(data) error`, and we could have another method `AppendReturning(&data) error` that requires a pointer to data, this data is queried right after inserting the element, that way we can capture automatic fields (timestamps, autoincrement IDs, etc). See https://github.com/upper/db/issues/99\r\n* ~~`Database.C()` and `Database.Collection()`. We're removing `C()` and changing `Collection()`. See: https://github.com/upper/db/issues/148~~ (done)\r\n* `Database.Use()` I don't think we need this, we can remove it. See https://github.com/upper/db/pull/156\r\n* `Database.Drop()` This is also not necessary and it could be harmful. See https://github.com/upper/db/pull/156\r\n* `Database.Setup` and `Database.Open`, I think we should use `Database.Open` and not both. See https://github.com/upper/db/pull/158\r\n* `Database.Transaction` should be `Database.NewTransaction`?\r\n* If we add `AppendReturning` we won't need `IDSetter`, `Int64IDSetter` and friends.\r\n* We don't really need `Constrainer`.\r\n\r\nCould you help me finding the best solution for this, @pkieltyka?"},"comment":{"url":"https://api.github.com/repos/upper/db/issues/comments/204807944","html_url":"https://github.com/upper/db/issues/149#issuecomment-204807944","issue_url":"https://api.github.com/repos/upper/db/issues/149","id":204807944,"user":{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false},"created_at":"2016-04-02T21:41:11Z","updated_at":"2016-04-02T21:41:11Z","body":"@pkieltyka I was experimenting with this `InsertReturning()` method because I think that can solve cases like https://github.com/upper/db/issues/99, it basically implements the pattern that users follow when they want to get a recently inserted element from the database, which is querying for it. The difference is that this is all done within a transaction to make sure that we won't be inserting an element and not getting what we inserted, see the example here: https://github.com/upper/db/blob/experimental/insert-returning/internal/testing/adapter.go.tpl#L120 and the implementation: https://github.com/upper/db/blob/experimental/insert-returning/postgresql/collection.go#L66\r\n\r\nSometimes we don't need to query what we inserted, for such cases we'll always have `Insert()`.\r\n\r\nWhat do you think of this proposal?"}}