Local queries (#641)

* Read local queries from pgweb home directory
* Refactor local query functionality
* Allow picking local query in the query tab
* WIP
* Disable local query dropdown during execution
* Only allow local queries running in a single session mode
* Add middleware to enforce local query endpoint availability
* Fix query check
* Add query store tests
* Make query store errors portable
* Skip building specific tests on windows
This commit is contained in:
Dan Sosedoff
2023-02-02 16:13:14 -06:00
committed by GitHub
parent 1c3ab1fd1c
commit 41bf189e6b
23 changed files with 884 additions and 12 deletions

View File

@@ -357,6 +357,7 @@
#input .actions #query_progress {
display: none;
float: left;
font-size: 12px;
line-height: 30px;
height: 30px;
color: #aaa;

View File

@@ -17,7 +17,7 @@
<script type="text/javascript" src="static/js/bootstrap-dropdown.js"></script>
<script type="text/javascript" src="static/js/utils.js"></script>
<script type="text/javascript" src="static/js/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript" src="static/js/app.js"></script>
<script type="text/javascript" src="static/js/app.js"></script>
<script type="text/javascript" src="static/js/base64.js"></script>
</head>
<body>
@@ -87,6 +87,13 @@
<li><a href="#" id="analyze">Analyze Query</a></li>
</ul>
</div>
<div id="load-query-dropdown" class="btn-group left" style="display: none">
<button id="load-local-query" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" disabled="disabled">
Template <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
</ul>
</div>
<div id="query_progress">Please wait, query is executing...</div>
<div class="pull-right">
<span id="result-rows-count"></span>

View File

@@ -178,6 +178,33 @@ function buildSchemaSection(name, objects) {
return section;
}
function loadLocalQueries() {
if (!appFeatures.local_queries) return;
$("body").on("click", "a.load-local-query", function(e) {
var id = $(this).data("id");
apiCall("get", "/local_queries/" + id, {}, function(resp) {
editor.setValue(resp.query);
editor.clearSelection();
});
});
apiCall("get", "/local_queries", {}, function(resp) {
if (resp.error) return;
var container = $("#load-query-dropdown").find(".dropdown-menu");
resp.forEach(function(item) {
var title = item.title || item.id;
$("<li><a href='#' class='load-local-query' data-id='" + item.id + "'>" + title + "</a></li>").appendTo(container);
});
if (resp.length > 0) $("#load-local-query").prop("disabled", "");
$("#load-query-dropdown").show();
});
}
function loadSchemas() {
$("#objects").html("");
@@ -738,13 +765,13 @@ function showActivityPanel() {
}
function showQueryProgressMessage() {
$("#run, #explain-dropdown-toggle, #csv, #json, #xml").prop("disabled", true);
$("#run, #explain-dropdown-toggle, #csv, #json, #xml, #load-local-query").prop("disabled", true);
$("#explain-dropdown").removeClass("open");
$("#query_progress").show();
}
function hideQueryProgressMessage() {
$("#run, #explain-dropdown-toggle, #csv, #json, #xml").prop("disabled", false);
$("#run, #explain-dropdown-toggle, #csv, #json, #xml, #load-local-query").prop("disabled", false);
$("#query_progress").hide();
}
@@ -1810,6 +1837,7 @@ $(document).ready(function() {
connected = true;
loadSchemas();
loadLocalQueries();
$("#current_database").text(resp.current_database);
$("#main").show();