From f673e7416f3a18a1ad9471d696782206114532f7 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 19 Jun 2026 17:14:33 -0700 Subject: [PATCH] Add create table execute-write template (#2794) Add a Create table starter template to the execute-write page, alongside the existing table-specific insert/update/delete templates. Keep template button clicks in-page by updating CodeMirror and the URL without collapsing the template controls. Refresh schema metadata after successful schema-changing execute-write statements so newly created tables appear immediately. --- datasette/app.py | 7 +- datasette/templates/execute_write.html | 71 ++++++++++---- datasette/views/execute_write.py | 33 +++++++ tests/test_queries.py | 127 +++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 18 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 545a65c8..139e4c34 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -625,9 +625,12 @@ class Datasette: return action return None - async def refresh_schemas(self): + async def refresh_schemas(self, *, force=False): # Throttle schema refreshes to at most once per second - if time.monotonic() - getattr(self, "_last_schema_refresh", 0) < 1.0: + if ( + not force + and time.monotonic() - getattr(self, "_last_schema_refresh", 0) < 1.0 + ): return self._last_schema_refresh = time.monotonic() if self._refresh_schemas_lock.locked(): diff --git a/datasette/templates/execute_write.html b/datasette/templates/execute_write.html index 949850ed..0d0a9931 100644 --- a/datasette/templates/execute_write.html +++ b/datasette/templates/execute_write.html @@ -93,20 +93,25 @@ form.sql.core input[data-execute-write-submit]:disabled { {% endif %}
- {% if write_template_tables %} + {% if write_create_table_template_sql or write_template_tables %}
Start with a template

- - + {% for table_name, table in write_template_tables|dictsort %} + + {% endfor %} + + {% for operation in write_template_operations %} + {% endfor %} - - {% for operation in write_template_operations %} - - {% endfor %} + {% endif %}

@@ -252,11 +257,12 @@ window.addEventListener("DOMContentLoaded", () => { }); -{% if write_template_tables %} +{% if write_create_table_template_sql or write_template_tables %}