{"html_url": "https://github.com/simonw/datasette/issues/1528#issuecomment-1151887842", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1528", "id": 1151887842, "node_id": "IC_kwDOBm6k_c5EqGni", "user": {"value": 25778, "label": "eyeseast"}, "created_at": "2022-06-10T03:23:08Z", "updated_at": "2022-06-10T03:23:08Z", "author_association": "CONTRIBUTOR", "body": "I just put together a version of this in a plugin: https://github.com/eyeseast/datasette-query-files. Happy to have any feedback.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1060631257, "label": "Add new `\"sql_file\"` key to Canned Queries in metadata?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1528#issuecomment-988468238", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1528", "id": 988468238, "node_id": "IC_kwDOBm6k_c466tQO", "user": {"value": 30934, "label": "20after4"}, "created_at": "2021-12-08T03:35:45Z", "updated_at": "2021-12-08T03:35:45Z", "author_association": "NONE", "body": "FWIW I implemented something similar with a bit of plugin code:\r\n\r\n```python\r\n@hookimpl\r\ndef canned_queries(datasette: Datasette, database: str) -> Mapping[str, str]:\r\n # load \"canned queries\" from the filesystem under\r\n # www/sql/db/query_name.sql\r\n queries = {}\r\n\r\n sqldir = Path(__file__).parent.parent / \"sql\"\r\n if database:\r\n sqldir = sqldir / database\r\n\r\n if not sqldir.is_dir():\r\n return queries\r\n\r\n for f in sqldir.glob('*.sql'):\r\n try:\r\n sql = f.read_text('utf8').strip()\r\n if not len(sql):\r\n log(f\"Skipping empty canned query file: {f}\")\r\n continue\r\n queries[f.stem] = { \"sql\": sql }\r\n except OSError as err:\r\n log(err)\r\n\r\n return queries\r\n\r\n\r\n\r\n```", "reactions": "{\"total_count\": 1, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 1, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1060631257, "label": "Add new `\"sql_file\"` key to Canned Queries in metadata?"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1528#issuecomment-975955589", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1528", "id": 975955589, "node_id": "IC_kwDOBm6k_c46K-aF", "user": {"value": 15178711, "label": "asg017"}, "created_at": "2021-11-22T22:00:30Z", "updated_at": "2021-11-22T22:00:30Z", "author_association": "CONTRIBUTOR", "body": "Oh, another thing to consider: I believe this would be the first `\"_file\"` key in datasette's metadata, compared to other `\"_url\"` keys like `\"license_url\"` or `\"about_url\"`. Not too sure what considerations to include with this (ex should missing files cause Datasette to stop before starting, should build scripts bundle these sql files somewhere during `datasette package`, etc.)", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1060631257, "label": "Add new `\"sql_file\"` key to Canned Queries in metadata?"}, "performed_via_github_app": null}