{"html_url": "https://github.com/simonw/datasette/issues/2049#issuecomment-1489526501", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2049", "id": 1489526501, "node_id": "IC_kwDOBm6k_c5YyF7l", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-03-30T00:44:05Z", "updated_at": "2023-03-30T00:44:05Z", "author_association": "OWNER", "body": "As part of this I should be able to figure out which bits of the new code I wrote for the table view should actually be shared with the query view. That stuff is mostly going to be from this commit: https://github.com/simonw/datasette/commit/d97e82df3c8a3f2e97038d7080167be9bb74a68d\r\n\r\nHere's the existing QueryView class I need to replace:\r\n\r\nhttps://github.com/simonw/datasette/blob/4c1e277edbd783d06840d3f9b20bf00783478ce4/datasette/views/database.py#L215-L532", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1646734246, "label": "Custom SQL queries should use new JSON ?_extra= format"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2049#issuecomment-1489530037", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2049", "id": 1489530037, "node_id": "IC_kwDOBm6k_c5YyGy1", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-03-30T00:50:30Z", "updated_at": "2023-03-30T00:50:30Z", "author_association": "OWNER", "body": "Two things to consider here: `_shape=` and `_extra=`.\r\n\r\nMost of the shapes make sense, with the exception of `?_shape=object` since we don't know which column we would use as a primary key.\r\n\r\nLooking at the (undocumented) list of extras from the table view, here are the ones I think make sense:\r\n\r\n- `count` - YES\r\n- `facet_results` - no\r\n- `facets_timed_out` - no\r\n- `suggested_facets` - no\r\n- `human_description_en` - no\r\n- `next_url` - MAYBE\r\n- `columns` - YES\r\n- `primary_keys` - no\r\n- `display_columns` - YES\r\n- `display_rows` - YES\r\n- `debug` - YES?\r\n- `request` - YES\r\n- `query` - YES\r\n- `metadata` - YES\r\n- `extras` - YES\r\n- `database` - YES\r\n- `table` - no\r\n- `database_color` - no?\r\n- `table_actions` - no\r\n- `filters` - no\r\n- `renderers` - YES\r\n- `custom_table_templates` - no\r\n- `sorted_facet_results` - no\r\n- `table_definition` - no\r\n- `view_definition` - no\r\n- `is_view` - no\r\n- `private` - YES\r\n- `expandable_columns` - no\r\n- `form_hidden_args` - no\r\n\r\nJust the YES ones:\r\n\r\n- `count` - this is new\r\n- `columns`\r\n- `display_columns`\r\n- `display_rows`\r\n- `debug`\r\n- `request`\r\n- `query`\r\n- `metadata`\r\n- `extras`\r\n- `database`\r\n- `renderers`\r\n- `private`\r\n\r\nThe `count` one is interesting - I think I can provide that by optionally running `select count(*) from (inner query)`. It's a new feature though and not one I want to expose on the HTML view since it could result in poor performance - but having it as an extra that API users can opt into may make sense.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1646734246, "label": "Custom SQL queries should use new JSON ?_extra= format"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2049#issuecomment-1489530555", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2049", "id": 1489530555, "node_id": "IC_kwDOBm6k_c5YyG67", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-03-30T00:51:27Z", "updated_at": "2023-03-30T00:51:27Z", "author_association": "OWNER", "body": "I'd really like to refactor all of the extras functions into a `datasette/extras.py` module. The table ones currently rely a LOT on local variables in scope though, so I would need to rewrite those such that EVERY dependency they take is passed to `asyncinject` explicitly.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1646734246, "label": "Custom SQL queries should use new JSON ?_extra= format"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2049#issuecomment-1498275621", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2049", "id": 1498275621, "node_id": "IC_kwDOBm6k_c5ZTd8l", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-04-05T23:23:01Z", "updated_at": "2023-04-05T23:23:01Z", "author_association": "OWNER", "body": "The default representation here can be even smaller.\r\n\r\nFor rows it's this:\r\n\r\n```json\r\n{\r\n \"ok\": true,\r\n \"next\": \"d,v\",\r\n \"rows\": [...]\r\n}\r\n```\r\nFor SQL queries I'm considering this:\r\n```json\r\n{\r\n \"ok\": true,\r\n \"rows\": [...]\r\n}\r\n```\r\nI considered adding `\"sql\"` and `\"params\"` too, but on further thought those would be entirely a waste of bytes the majority of the time. If a user wants those they can request them with an `?_extra=query` as seen here:\r\n\r\nhttp://localhost:8001/content/releases.json?_size=0&_extra=query\r\n\r\n```json\r\n{\r\n \"ok\": true,\r\n \"next\": null,\r\n \"query\": {\r\n \"sql\": \"select html_url, id, author, node_id, tag_name, target_commitish, name, draft, prerelease, created_at, published_at, body, repo, reactions, mentions_count from releases order by id limit 1\",\r\n \"params\": {}\r\n },\r\n \"rows\": []\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": 1646734246, "label": "Custom SQL queries should use new JSON ?_extra= format"}, "performed_via_github_app": null}