Skip to content

Commit 7894516

Browse files
committed
Add server settings view
1 parent e6df3d1 commit 7894516

File tree

8 files changed

+61
-2
lines changed

8 files changed

+61
-2
lines changed

pkg/api/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ func GetConnectionInfo(c *gin.Context) {
486486
successResponse(c, info)
487487
}
488488

489+
// GetServerSettings renders a list of all server settings
490+
func GetServerSettings(c *gin.Context) {
491+
res, err := DB(c).ServerSettings()
492+
serveResult(c, res, err)
493+
}
494+
489495
// GetActivity renders a list of running queries
490496
func GetActivity(c *gin.Context) {
491497
res, err := DB(c).Activity()

pkg/api/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func SetupRoutes(router *gin.Engine) {
3535
api.POST("/switchdb", SwitchDb)
3636
api.GET("/databases", GetDatabases)
3737
api.GET("/connection", GetConnectionInfo)
38+
api.GET("/server_settings", GetServerSettings)
3839
api.GET("/activity", GetActivity)
3940
api.GET("/schemas", GetSchemas)
4041
api.GET("/objects", GetObjects)

pkg/client/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ func (client *Client) TablesStats() (*Result, error) {
386386
return client.query(statements.TablesStats)
387387
}
388388

389+
func (client *Client) ServerSettings() (*Result, error) {
390+
return client.query(statements.Settings)
391+
}
392+
389393
// Returns all active queriers on the server
390394
func (client *Client) Activity() (*Result, error) {
391395
if client.serverType == cockroachType {

pkg/client/client_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/sosedoff/pgweb/pkg/command"
15-
1614
"github.com/stretchr/testify/assert"
1715
"github.com/stretchr/testify/require"
16+
17+
"github.com/sosedoff/pgweb/pkg/command"
1818
)
1919

2020
var (
@@ -717,6 +717,32 @@ func testConnContext(t *testing.T) {
717717
assert.Equal(t, "default", result.Mode)
718718
}
719719

720+
func testServerSettings(t *testing.T) {
721+
expectedColumns := []string{
722+
"name",
723+
"setting",
724+
"unit",
725+
"category",
726+
"short_desc",
727+
"extra_desc",
728+
"context",
729+
"vartype",
730+
"source",
731+
"min_val",
732+
"max_val",
733+
"enumvals",
734+
"boot_val",
735+
"reset_val",
736+
"sourcefile",
737+
"sourceline",
738+
"pending_restart",
739+
}
740+
741+
result, err := testClient.ServerSettings()
742+
assert.NoError(t, err)
743+
assert.Equal(t, expectedColumns, result.Columns)
744+
}
745+
720746
func TestAll(t *testing.T) {
721747
if onWindows() {
722748
t.Log("Unit testing on Windows platform is not supported.")
@@ -756,6 +782,7 @@ func TestAll(t *testing.T) {
756782
testDumpExport(t)
757783
testTablesStats(t)
758784
testConnContext(t)
785+
testServerSettings(t)
759786

760787
teardownClient()
761788
teardown(t, true)

pkg/statements/sql.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ var (
4747
//go:embed sql/function.sql
4848
Function string
4949

50+
//go:embed sql/settings.sql
51+
Settings string
52+
5053
// Activity queries for specific PG versions
5154
Activity = map[string]string{
5255
"default": "SELECT * FROM pg_stat_activity WHERE datname = current_database()",

pkg/statements/sql/settings.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM pg_settings

static/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ <h3 class="text-center">SSH Connection</h3>
327327
<li><a href="#" data-action="show_db_stats">Show Database Stats</a></li>
328328
<li><a href="#" data-action="download_db_stats">Download Database Stats</a></li>
329329
<li class="divider"></li>
330+
<li><a href="#" data-action="server_settings">Show Server Settings</a></li>
331+
<li class="divider"></li>
330332
<li><a href="#" data-action="export">Export SQL dump</a></li>
331333
</ul>
332334
</div>

static/js/app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function apiCall(method, path, params, cb) {
9999

100100
function getInfo(cb) { apiCall("get", "/info", {}, cb); }
101101
function getConnection(cb) { apiCall("get", "/connection", {}, cb); }
102+
function getServerSettings(cb) { apiCall("get", "/server_settings", {}, cb); }
102103
function getSchemas(cb) { apiCall("get", "/schemas", {}, cb); }
103104
function getObjects(cb) { apiCall("get", "/objects", {}, cb); }
104105
function getTables(cb) { apiCall("get", "/tables", {}, cb); }
@@ -678,6 +679,17 @@ function downloadDatabaseStats() {
678679
openInNewWindow("api/tables_stats", { format: "csv", export: "true" });
679680
}
680681

682+
function showServerSettings() {
683+
getServerSettings(function(data) {
684+
buildTable(data);
685+
686+
setCurrentTab("table_content");
687+
$("#input").hide();
688+
$("#body").prop("class", "full");
689+
$("#results").addClass("no-crop");
690+
});
691+
}
692+
681693
function showTableStructure() {
682694
var name = getCurrentObject().name;
683695

@@ -1280,6 +1292,9 @@ function bindCurrentDatabaseMenu() {
12801292
case "download_db_stats":
12811293
downloadDatabaseStats();
12821294
break;
1295+
case "server_settings":
1296+
showServerSettings();
1297+
break;
12831298
case "export":
12841299
openInNewWindow("api/export");
12851300
break;

0 commit comments

Comments
 (0)