{"html_url": "https://github.com/simonw/sqlite-utils/issues/267#issuecomment-866184260", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/267", "id": 866184260, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NjE4NDI2MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T17:26:18Z", "updated_at": "2021-06-22T17:27:27Z", "author_association": "OWNER", "body": "If an`.update()` method doesn't work because it collides with an existing dictionary method a `.pk` property could still be nice:\r\n```python\r\nfor row in db[\"sometable\"].rows:\r\n db[\"sometable\"].update(row.pk, {\"modified\": 1})\r\n```\r\n \r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 915421499, "label": "row.update() or row.pk"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/267#issuecomment-866182655", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/267", "id": 866182655, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NjE4MjY1NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T17:24:03Z", "updated_at": "2021-06-22T17:24:03Z", "author_association": "OWNER", "body": "I'm re-opening this as a research task because it may be possible to cleanly implement this using a `dict` subclass - some notes on that here: https://treyhunner.com/2019/04/why-you-shouldnt-inherit-from-list-and-dict-in-python/\r\n\r\nSince this would just be for adding methods (and maybe a property for returning the primary keys for a row) the usual disadvantages of subclassing `dict` described in that article shouldn't apply.\r\n\r\nOne catch: dictionaries already have a `.update()` method! So would have to pick another name.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 915421499, "label": "row.update() or row.pk"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/267#issuecomment-862494864", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/267", "id": 862494864, "node_id": "MDEyOklzc3VlQ29tbWVudDg2MjQ5NDg2NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-16T15:51:28Z", "updated_at": "2021-06-16T16:26:15Z", "author_association": "OWNER", "body": "I did add a slightly clumsy mechanism recently to help a bit here though: the `pks_and_rows_where()` method: https://sqlite-utils.datasette.io/en/stable/python-api.html#listing-rows-with-their-primary-keys\r\n\r\nMore details in the issue for that feature: #240\r\n\r\nThe idea here is that if you want to call update you need the primary key for the row - so you can do this:\r\n\r\n```python\r\nfor pk, row in db[\"sometable\"].pks_and_rows_where():\r\n db[\"sometable\"].update(pk, {\"modified\": 1}\")\r\n```\r\nThe `pk` may end up as a single value or a tuple depending on if the table has a compound primary key - but you don't need to worry about that if you use this method as it will return the correct primary key value for you.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 915421499, "label": "row.update() or row.pk"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/267#issuecomment-862493179", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/267", "id": 862493179, "node_id": "MDEyOklzc3VlQ29tbWVudDg2MjQ5MzE3OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-16T15:49:13Z", "updated_at": "2021-06-16T15:49:13Z", "author_association": "OWNER", "body": "The big challenge here is that the rows returned by this library aren't objects, they are Python dictionaries - so adding methods to them isn't possible without changing the type that is returned by these methods.\r\n\r\nPart of the philosophy of the library is that it should make it as easy as possible to round-trip between Python dictionaries and SQLite table data, so I don't think adding methods like this is going to fit.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 915421499, "label": "row.update() or row.pk"}, "performed_via_github_app": null}