* Add SQL query executor

* Move mermaid.min.js to static asset
* Create templates for sql logic
This commit is contained in:
Peter Stockings
2024-11-06 23:25:25 +11:00
parent 3a07b9d97f
commit 0f55d42f22
9 changed files with 2147 additions and 19 deletions

View File

@@ -0,0 +1,7 @@
<div class="overflow-auto" style="max-height: 80vh;">
<div class="mermaid" style="opacity: 0;" _="on load
mermaid.init(undefined, this)
set me.style.opacity to '1'">
{{ mermaid_code }}
</div>
</div>

View File

@@ -0,0 +1,37 @@
<div id="sql-query">
{% if error %}
<div class="bg-red-200 text-red-800 p-3 rounded mb-4">
<strong>Error:</strong> {{ error }}
</div>
{% endif %}
<form method="POST" hx-post="{{ url_for('sql_query') }}" hx-target="#sql-query">
<textarea name="query" rows="5" class="w-full p-2 border rounded mb-4"
placeholder="Enter your SQL query here..." required>{{ query }}</textarea>
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded">Execute</button>
</form>
<div class="mt-6">
{% if results %}
<table class="min-w-full bg-white">
<thead>
<tr>
{% for col in columns %}
<th class="py-2 px-4 border-b">{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in results %}
<tr class="text-center">
{% for col in columns %}
<td class="py-2 px-4 border-b">{{ row[col] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</div>