{"html_url": "https://github.com/simonw/sqlite-utils/issues/25#issuecomment-501548676", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/25", "id": 501548676, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTU0ODY3Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T04:58:12Z", "updated_at": "2019-06-13T04:58:12Z", "author_association": "OWNER", "body": "I'm going to reuse the `ForeignKey` named tuple here:\r\n\r\nhttps://github.com/simonw/sqlite-utils/blob/d645032cfa4edbccd0542eecdddca29edf9f7b07/sqlite_utils/db.py#L17-L19", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449848803, "label": "Allow .insert(..., foreign_keys=()) to auto-detect table and primary key"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/25#issuecomment-501548097", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/25", "id": 501548097, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTU0ODA5Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T04:54:33Z", "updated_at": "2019-06-13T04:54:33Z", "author_association": "OWNER", "body": "Still need to add this mechanism to `.create_table()` - this code here is all that needs to be modified - it needs to learn to deal with the alternative syntax for foreign keys and guess the missing data if necessary:\r\n\r\nhttps://github.com/simonw/sqlite-utils/blob/d645032cfa4edbccd0542eecdddca29edf9f7b07/sqlite_utils/db.py#L115-L119", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449848803, "label": "Allow .insert(..., foreign_keys=()) to auto-detect table and primary key"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/25#issuecomment-501517535", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/25", "id": 501517535, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTUxNzUzNQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T01:50:34Z", "updated_at": "2019-06-13T01:50:34Z", "author_association": "OWNER", "body": "If I'm going to do this then I should make the `other_table` and `other_column` arguments optional here too:\r\n\r\nhttps://github.com/simonw/sqlite-utils/blob/2fed87da6ea990d295672e4db2c8ae97b787913e/sqlite_utils/cli.py#L201-L215", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 449848803, "label": "Allow .insert(..., foreign_keys=()) to auto-detect table and primary key"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/25#issuecomment-501516797", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/25", "id": 501516797, "node_id": "MDEyOklzc3VlQ29tbWVudDUwMTUxNjc5Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-06-13T01:46:36Z", "updated_at": "2019-06-13T01:47:35Z", "author_association": "OWNER", "body": "Maybe `foreign_keys` could even optionally just be a list of columns - it could then attempt to detect the related tables based on some rules-of-thumb and raise an error if there's no obvious candidate.\r\n\r\nRules:\r\n* If the column name ends in `_id`, remove that suffix and look for a matching table.\r\n* Try for a table which is the column name without the `_id` suffix with an `s` appended to it\r\n* Try for a table that's the exact match for the column name\r\n\r\nIf none of these rules match, raise an error.\r\n\r\nSo the above example could be further simplified to:\r\n```python\r\ndb[\"usages\"].insert_all(\r\n usages_to_insert,\r\n foreign_keys=[\"line_id\", \"definition_id\"]\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": 449848803, "label": "Allow .insert(..., foreign_keys=()) to auto-detect table and primary key"}, "performed_via_github_app": null}