{"html_url": "https://github.com/simonw/sqlite-utils/issues/37#issuecomment-509681590", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/37", "id": 509681590, "node_id": "MDEyOklzc3VlQ29tbWVudDUwOTY4MTU5MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-07-09T15:07:12Z", "updated_at": "2021-06-22T18:17:53Z", "author_association": "OWNER", "body": "Here's a magic incantation for generating types detected through running the tests with https://github.com/Instagram/MonkeyType\r\n\r\n```\r\npip install pytest-monkeytype\r\npytest --monkeytype-output=./monkeytype.sqlite3\r\nmonkeytype list-modules\r\nmonkeytype apply sqlite_utils.utils\r\nmonkeytype apply sqlite_utils.cli\r\nmonkeytype apply sqlite_utils.db\r\n```\r\n\r\nHere's the result: https://github.com/simonw/sqlite-utils/commit/d18c694fc25b7dd3d76e250c77ddf56d10ddf935", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 465815372, "label": "Experiment with type hints"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/290#issuecomment-865491922", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/290", "id": 865491922, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NTQ5MTkyMg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T03:05:35Z", "updated_at": "2021-06-22T03:05:35Z", "author_association": "OWNER", "body": "Potential names:\r\n\r\n- `db.query(sql)` - it's weird to have both this and `db.execute()` but it is at least short and memorable\r\n- `db.sql(sql)`\r\n- `db.execute_d(sql)` - ugly\r\n- `db.execute_dicts(sql)` - confusing\r\n- `db.execute_sql(sql)` - easily confused with `db.execute(sql)`\r\n\r\nI think `db.query(sql)` may be the best option here.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 926777310, "label": "`db.query()` method (renamed `db.execute_returning_dicts()`)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/290#issuecomment-865495370", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/290", "id": 865495370, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NTQ5NTM3MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T03:14:30Z", "updated_at": "2021-06-22T03:14:30Z", "author_association": "OWNER", "body": "One small problem with the existing method:\r\nhttps://github.com/simonw/sqlite-utils/blob/8cedc6a8b29180e68326f6b76f249d5e39e4b591/sqlite_utils/db.py#L362-L365\r\n\r\nIt returns a full list, but what if the user would rather have a generator they can iterate over without loading the results into memory in one go?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 926777310, "label": "`db.query()` method (renamed `db.execute_returning_dicts()`)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/290#issuecomment-865497846", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/290", "id": 865497846, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NTQ5Nzg0Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T03:21:38Z", "updated_at": "2021-06-22T03:21:38Z", "author_association": "OWNER", "body": "The Python docs say: https://docs.python.org/3/library/sqlite3.html\r\n\r\n> To retrieve data after executing a SELECT statement, you can either treat the cursor as an iterator, call the cursor\u2019s `fetchone()` method to retrieve a single matching row, or call `fetchall()` to get a list of the matching rows.\r\n\r\nLooking at the C source code, both `fetchmany()` and `fetchall()` work under the hood by assembling a Python list: https://github.com/python/cpython/blob/be1cb3214d09d4bf0288bc45f3c1f167f67e4514/Modules/_sqlite/cursor.c#L907-L972 - see calls to `PyList_Append()`\r\n\r\nSo it looks like the most efficient way to iterate over a cursor may well be `for row in cursor:` - which I think calls this C function: https://github.com/python/cpython/blob/be1cb3214d09d4bf0288bc45f3c1f167f67e4514/Modules/_sqlite/cursor.c#L813-L876", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 926777310, "label": "`db.query()` method (renamed `db.execute_returning_dicts()`)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/290#issuecomment-865510796", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/290", "id": 865510796, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NTUxMDc5Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T04:04:40Z", "updated_at": "2021-06-22T04:04:48Z", "author_association": "OWNER", "body": "Still needs documentation, which will involve rewriting the whole [Executing queries](https://sqlite-utils.datasette.io/en/3.11/python-api.html#executing-queries) section.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 926777310, "label": "`db.query()` method (renamed `db.execute_returning_dicts()`)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/290#issuecomment-865511810", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/290", "id": 865511810, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NTUxMTgxMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T04:07:34Z", "updated_at": "2021-06-22T18:26:21Z", "author_association": "OWNER", "body": "That documentation section is pretty weak at the moment - here's the whole thing:\r\n\r\n> ### Executing queries\r\n>\r\n> The `db.execute()` and `db.executescript()` methods provide wrappers around `.execute()` and `.executescript()` on the underlying SQLite connection. These wrappers log to the tracer function if one has been registered.\r\n> ```python\r\n> db = Database(memory=True)\r\n> db[\"dogs\"].insert({\"name\": \"Cleo\"})\r\n> db.execute(\"update dogs set name = 'Cleopaws'\")\r\n> ```\r\n> You can pass parameters as an optional second argument, using either a list or a dictionary. These will be correctly quoted and escaped.\r\n> ```python\r\n> # Using ? and a list:\r\n> db.execute(\"update dogs set name = ?\", [\"Cleopaws\"])\r\n> # Or using :name and a dictionary:\r\n> db.execute(\"update dogs set name = :name\", {\"name\": \"Cleopaws\"})\r\n> ```\r\n\r\n- Talks about `.execute()` - I want to talk about `.query()` instead\r\n- Doesn't clarify that `.execute()` returns a `Cursor` - and assumes you know what to do with one\r\n- Doesn't show an example of a `select` query at all\r\n- The \"tracer function\" bit is confusing (should at least link to docs further down)\r\n- For `UPDATE` should show how to access the number of rows modified (probably using `.execute()` there)\r\n\r\nIt does at least cover the two types of parameters, though that could be bulked out.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 926777310, "label": "`db.query()` method (renamed `db.execute_returning_dicts()`)"}, "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-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/289#issuecomment-866219755", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/289", "id": 866219755, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NjIxOTc1NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-06-22T18:13:26Z", "updated_at": "2021-06-22T18:13:26Z", "author_association": "OWNER", "body": "Thanks @adamchainz - `mypy` now has a foothold on this project (and runs in CI).", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 925677191, "label": "Mypy fixes for rows_from_file()"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/289#issuecomment-866241836", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/289", "id": 866241836, "node_id": "MDEyOklzc3VlQ29tbWVudDg2NjI0MTgzNg==", "user": {"value": 857609, "label": "adamchainz"}, "created_at": "2021-06-22T18:44:36Z", "updated_at": "2021-06-22T18:44:36Z", "author_association": "NONE", "body": "Great!", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 925677191, "label": "Mypy fixes for rows_from_file()"}, "performed_via_github_app": null}