Database UI

/views/vdatabase/Statement.html (3.5 KB)

  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{% import (
"{{{ .Package }}}/app"
"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/database"
"{{{ .Package }}}/app/util"
"{{{ .Package }}}/views/components"
"{{{ .Package }}}/views/layout"
) %}

{% code type Statement struct {
layout.Basic
Statement *database.DebugStatement
} %}

{% func (p *Statement) Body(as *app.State, ps *cutil.PageState) %}
{%- code s := p.Statement -%}
<div class="card">
<div class="right">{%s util.MicrosToMillis(s.Timing) %} elapsed</div>
<h3>{%= components.SVGRefIcon(`database`, ps) %}Statement [{%d p.Statement.Index %}]</h3>
<div class="right">{%d s.Count %} rows returned</div>
<em>{%s s.Message %}</em>
{%- if s.Error != "" -%}
<div class="mt error">{%s s.Error %}</div>
{%- endif -%}
<div class="mt">
<ul class="accordion">
<li>
<input id="accordion-sql" type="checkbox" hidden />
<label for="accordion-sql">{%= components.ExpandCollapse(3, ps) %} SQL</label>
<div class="bd"><div><div>
{%= statementSQL(s) %}
</div></div></div>
</li>
{%- if len(s.Values) > 0 -%}
<li>
<input id="accordion-values" type="checkbox" hidden />
<label for="accordion-values">{%= components.ExpandCollapse(3, ps) %} Values</label>
<div class="bd"><div><div>
{%= statementValues(s) %}
</div></div></div>
</li>
{%- endif -%}
<li>
<input id="accordion-out" type="checkbox" hidden />
<label for="accordion-out">{%= components.ExpandCollapse(3, ps) %} Result</label>
<div class="bd"><div><div>
{%= statementOut(s) %}
</div></div></div>
</li>
{%- if len(s.Extra) > 0 -%}
<li>
<input id="accordion-extra" type="checkbox" hidden />
<label for="accordion-extra">{%= components.ExpandCollapse(3, ps) %} Query Plan</label>
<div class="bd"><div><div>
{%= components.DisplayMaps(s.Extra, nil, true, ps) %}
</div></div></div>
</li>
{%- endif -%}
</ul>
</div>
</div>
{% endfunc %}

{% func statementSQL(s *database.DebugStatement) %}
{%- code out, _ := cutil.FormatLang(s.SQL, "sql") -%}
{%s= out %}
{% endfunc %}

{% func statementValues(s *database.DebugStatement) %}
<div class="overflow full-width">
<table>
<thead>
<tr>
<th>#</th>
<th>Values</th>
</tr>
</thead>
<tbody>
{%- for idx, v := range s.Values -%}
<tr>
<td>{%d idx+1 %}</td>
<td>{%= components.JSON(v) %}</td>
</tr>
{%- endfor -%}
</tbody>
</table>
</div>
{% endfunc %}

{% func statementOut(s *database.DebugStatement) %}
{%- if len(s.Out) == 0 -%}
<em>no results</em>
{%- else -%}
<div class="overflow full-width">
<table>
<thead>
<tr>
<th class="shrink">Idx</th>
<th>Result</th>
</tr>
</thead>
<tbody>
{%- for idx, v := range s.Out -%}
<tr>
<td>{%d idx+1 %}</td>
<td>{%= components.JSON(v) %}</td>
</tr>
{%- endfor -%}
{%- if s.Count > len(s.Out) -%}
<tr>
<td colspan="2">...and {%d s.Count - len(s.Out) %} additional rows</td>
</tr>
{%- endif -%}
</tbody>
</table>
</div>
{%- endif -%}
{% endfunc %}