{"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973820125", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973820125, "node_id": "IC_kwDOCGYnMM46C1Dd", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T07:25:55Z", "updated_at": "2021-11-19T07:25:55Z", "author_association": "OWNER", "body": "`alter=True` doesn't make sense to support here either, because `.lookup()` already adds missing columns: https://github.com/simonw/sqlite-utils/blob/3b8abe608796e99e4ffc5f3f4597a85e605c0e9b/sqlite_utils/db.py#L2743-L2746", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973802998", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973802998, "node_id": "IC_kwDOCGYnMM46Cw32", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T06:59:22Z", "updated_at": "2021-11-19T06:59:32Z", "author_association": "OWNER", "body": "I don't think I need the `DEFAULT` defaults for `.insert()` either, since it just passes through to `.insert()`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973802766", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973802766, "node_id": "IC_kwDOCGYnMM46Cw0O", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T06:58:45Z", "updated_at": "2021-11-19T06:58:45Z", "author_association": "OWNER", "body": "And neither does `hash_id`. On that basis I'm going to specifically list the ones that DO make sense, and hope that I remember to add any new ones in the future. I can add a code comment hint to `.insert()` about that.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973802469", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973802469, "node_id": "IC_kwDOCGYnMM46Cwvl", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T06:58:03Z", "updated_at": "2021-11-19T06:58:03Z", "author_association": "OWNER", "body": "Also: I don't think `ignore=` and `replace=` make sense in the context of `lookup()`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973802308", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973802308, "node_id": "IC_kwDOCGYnMM46CwtE", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T06:57:37Z", "updated_at": "2021-11-19T06:57:37Z", "author_association": "OWNER", "body": "Here's the current full method signature for `.insert()`: https://github.com/simonw/sqlite-utils/blob/3b8abe608796e99e4ffc5f3f4597a85e605c0e9b/sqlite_utils/db.py#L2462-L2477\r\n\r\nI could add a test which uses introspection (`inspect.signature(method).parameters`) to confirm that `.lookup()` has a super-set of the arguments accepted by `.insert()`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973801650", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973801650, "node_id": "IC_kwDOCGYnMM46Cwiy", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T06:55:56Z", "updated_at": "2021-11-19T06:55:56Z", "author_association": "OWNER", "body": "`pk` needs to be an explicit argument to `.lookup()`. The rest could be `**kwargs` passed through to `.insert()`, like this hacked together version (docstring removed for brevity):\r\n\r\n```python\r\n def lookup(\r\n self,\r\n lookup_values: Dict[str, Any],\r\n extra_values: Optional[Dict[str, Any]] = None,\r\n pk=\"id\",\r\n **insert_kwargs,\r\n ):\r\n \"\"\"\r\n assert isinstance(lookup_values, dict)\r\n if extra_values is not None:\r\n assert isinstance(extra_values, dict)\r\n combined_values = dict(lookup_values)\r\n if extra_values is not None:\r\n combined_values.update(extra_values)\r\n if self.exists():\r\n self.add_missing_columns([combined_values])\r\n unique_column_sets = [set(i.columns) for i in self.indexes]\r\n if set(lookup_values.keys()) not in unique_column_sets:\r\n self.create_index(lookup_values.keys(), unique=True)\r\n wheres = [\"[{}] = ?\".format(column) for column in lookup_values]\r\n rows = list(\r\n self.rows_where(\r\n \" and \".join(wheres), [value for _, value in lookup_values.items()]\r\n )\r\n )\r\n try:\r\n return rows[0][pk]\r\n except IndexError:\r\n return self.insert(combined_values, pk=pk, **insert_kwargs).last_pk\r\n else:\r\n pk = self.insert(combined_values, pk=pk, **insert_kwargs).last_pk\r\n self.create_index(lookup_values.keys(), unique=True)\r\n return pk\r\n```\r\nI think I'll explicitly list the parameters, mainly so they can be typed and covered by automatic documentation.\r\n\r\nI do worry that I'll add more keyword arguments to `.insert()` in the future and forget to mirror them to `.lookup()` though.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/342#issuecomment-973800795", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/342", "id": 973800795, "node_id": "IC_kwDOCGYnMM46CwVb", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-19T06:54:08Z", "updated_at": "2021-11-19T06:54:08Z", "author_association": "OWNER", "body": "Looking at the code for `lookup()` it currently hard-codes `pk` to `\"id\"` - but it actually only calls `.insert()` in two places, both of which could be passed extra arguments.\r\n\r\nhttps://github.com/simonw/sqlite-utils/blob/3b8abe608796e99e4ffc5f3f4597a85e605c0e9b/sqlite_utils/db.py#L2756-L2763", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1058196641, "label": "Extra options to `lookup()` which get passed to `insert()`"}, "performed_via_github_app": null}