Button to format SQL, closes #136

SQL code will be formatted on page load, and can additionally
be formatted by clicking the "Format SQL" button.

Thanks, @rixx!
This commit is contained in:
Tobias Kunze 2019-10-14 05:46:12 +02:00 committed by Simon Willison
commit af2e6a5cf1
6 changed files with 50 additions and 9 deletions

View file

@ -37,7 +37,7 @@
{% if editable and config.allow_sql %}
<p><textarea id="sql-editor" name="sql">{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}</textarea></p>
{% else %}
<pre>{% if query %}{{ query.sql }}{% endif %}</pre>
<pre id="sql-query">{% if query %}{{ query.sql }}{% endif %}</pre>
{% endif %}
{% else %}
<input type="hidden" name="sql" value="{% if query and query.sql %}{{ query.sql }}{% else %}select * from {{ tables[0].name|escape_sqlite }}{% endif %}">
@ -49,7 +49,10 @@
<p><label for="qp{{ loop.index }}">{{ name }}</label> <input type="text" id="qp{{ loop.index }}" name="{{ name }}" value="{{ value }}"></p>
{% endfor %}
{% endif %}
<p><input type="submit" value="Run SQL"></p>
<p>
<button id="sql-format" type="button" hidden>Format SQL</button>
<input type="submit" value="Run SQL">
</p>
</form>
{% if display_rows %}