{"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786037219", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786037219, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAzNzIxOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T16:39:23Z", "updated_at": "2021-02-25T16:39:23Z", "author_association": "OWNER", "body": "Example from the docs:\r\n```pycon\r\n>>> db = sqlite_utils.Database(memory=True)\r\n>>> db[\"dogs\"].insert({\"name\": \"Cleo\"})\r\n>>> for pk, row in db[\"dogs\"].pks_and_rows_where():\r\n... print(pk, row)\r\n1 {'rowid': 1, 'name': 'Cleo'}\r\n\r\n>>> db[\"dogs_with_pk\"].insert({\"id\": 5, \"name\": \"Cleo\"}, pk=\"id\")\r\n>>> for pk, row in db[\"dogs_with_pk\"].pks_and_rows_where():\r\n... print(pk, row)\r\n5 {'id': 5, 'name': 'Cleo'}\r\n\r\n>>> db[\"dogs_with_compound_pk\"].insert(\r\n... {\"species\": \"dog\", \"id\": 3, \"name\": \"Cleo\"},\r\n... pk=(\"species\", \"id\")\r\n... )\r\n>>> for pk, row in db[\"dogs_with_compound_pk\"].pks_and_rows_where():\r\n... print(pk, row)\r\n('dog', 3) {'species': 'dog', 'id': 3, 'name': 'Cleo'}\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786036355", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786036355, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAzNjM1NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T16:38:07Z", "updated_at": "2021-02-25T16:38:07Z", "author_association": "OWNER", "body": "Documentation: https://sqlite-utils.datasette.io/en/latest/python-api.html#listing-rows-with-their-primary-keys", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786016380", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786016380, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAxNjM4MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T16:10:01Z", "updated_at": "2021-02-25T16:10:01Z", "author_association": "OWNER", "body": "I prototyped this and I like it:\r\n```\r\nIn [1]: import sqlite_utils\r\nIn [2]: db = sqlite_utils.Database(\"/Users/simon/Dropbox/Development/datasette/fixtures.db\")\r\nIn [3]: list(db[\"compound_primary_key\"].pks_and_rows_where())\r\nOut[3]: [(('a', 'b'), {'pk1': 'a', 'pk2': 'b', 'content': 'c'})]\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786007209", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786007209, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAwNzIwOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T15:57:50Z", "updated_at": "2021-02-25T15:57:50Z", "author_association": "OWNER", "body": "`table.pks_and_rows_where(...)` is explicit and I think less ambiguous than the other options.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786006794", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786006794, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAwNjc5NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T15:57:17Z", "updated_at": "2021-02-25T15:57:28Z", "author_association": "OWNER", "body": "I quite like `pks_with_rows_where(...)` - but grammatically it suggests it will return the primary keys that exist where their rows match the criteria - \"pks with rows\" can be interpreted as \"pks for the rows that...\" as opposed to \"pks accompanied by rows\"", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786005078", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786005078, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAwNTA3OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T15:54:59Z", "updated_at": "2021-02-25T15:56:16Z", "author_association": "OWNER", "body": "Is `pk_rows_where()` a good name? It sounds like it returns \"primary key rows\" which isn't a thing. It actually returns rows along with their primary key.\r\n\r\nOther options:\r\n\r\n- `table.rows_with_pk_where(...)` - should this return `(row, pk)` rather than `(pk, row)`?\r\n- `table.rows_where_pk(...)`\r\n- `table.pk_and_rows_where(...)`\r\n- `table.pk_with_rows_where(...)`\r\n- `table.pks_with_rows_where(...)` - because rows is pluralized, so pks should be pluralized too?\r\n- `table.pks_rows_where(...)`", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/240#issuecomment-786001768", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/240", "id": 786001768, "node_id": "MDEyOklzc3VlQ29tbWVudDc4NjAwMTc2OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-02-25T15:50:28Z", "updated_at": "2021-02-25T15:52:12Z", "author_association": "OWNER", "body": "One option: `.rows_where()` could grow a `ensure_pk=True` option which checks to see if the table is a `rowid` table and, if it is, includes that in the `select`.\r\n\r\nOr... how about you can call `.rows_where(..., pks=True)` and it will yield `(pk, rowdict)` tuple pairs instead of just returning the sequence of dictionaries?\r\n\r\nI'm always a little bit nervous of methods that vary their return type based on their arguments. Maybe this would be a separate method instead?\r\n```python\r\n for pk, row in table.pk_rows_where(...):\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": 816560819, "label": "table.pks_and_rows_where() method returning primary keys along with the rows"}, "performed_via_github_app": null}