Skip to content

Commit

Permalink
Rename NewPGresult to NewPGresultQuery.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Mar 6, 2021
1 parent d3c97a1 commit 390bc13
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/stat/postgres.go
Expand Up @@ -30,7 +30,7 @@ func collectPostgresStat(db *postgres.DB, version int, pgss bool, itv int, query
pgstat.Activity = activity

// Read stat
res, err := NewPGresult(db, query)
res, err := NewPGresultQuery(db, query)
if err != nil {
return pgstat, err
}
Expand Down Expand Up @@ -166,8 +166,8 @@ type PGresult struct {
Valid bool /* Used for result invalidations, on context switching for example */
}

// NewPGresult does query and wraps returned result into PGresult.
func NewPGresult(db *postgres.DB, query string) (PGresult, error) {
// NewPGresultQuery creates PGresult using passed database connection and query.
func NewPGresultQuery(db *postgres.DB, query string) (PGresult, error) {
if query == "" {
return PGresult{}, fmt.Errorf("no query defined")
}
Expand Down
8 changes: 4 additions & 4 deletions internal/stat/postgres_test.go
Expand Up @@ -111,7 +111,7 @@ func TestGetPostgresProperties(t *testing.T) {
assert.Error(t, err)
}

func TestNewPGresult(t *testing.T) {
func TestNewPGresultQuery(t *testing.T) {
conn, err := postgres.NewTestConnect()
assert.NoError(t, err)

Expand All @@ -124,17 +124,17 @@ func TestNewPGresult(t *testing.T) {
{{String: "3", Valid: true}, {String: "", Valid: false}, {String: "", Valid: false}, {String: "", Valid: false}},
},
}
got, err := NewPGresult(conn, "SELECT * FROM (VALUES (1,'one',10,11.1), (2,'two',20,22.2), (3,NULL,NULL,NULL)) AS t (id,name,v1,v2)")
got, err := NewPGresultQuery(conn, "SELECT * FROM (VALUES (1,'one',10,11.1), (2,'two',20,22.2), (3,NULL,NULL,NULL)) AS t (id,name,v1,v2)")
assert.NoError(t, err)
assert.Equal(t, want, got)

// testing empty query
_, err = NewPGresult(conn, "")
_, err = NewPGresultQuery(conn, "")
assert.Error(t, err)

// testing with already closed conn
conn.Close()
_, err = NewPGresult(conn, "SELECT 1")
_, err = NewPGresultQuery(conn, "SELECT 1")
assert.Error(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion record/recorder.go
Expand Up @@ -100,7 +100,7 @@ func (c *tarRecorder) collect(dbConfig postgres.Config, views view.Views) (map[s
stats := map[string]stat.PGresult{}

for k, v := range views {
res, err := stat.NewPGresult(db, v.Query)
res, err := stat.NewPGresultQuery(db, v.Query)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion top/pgconfig.go
Expand Up @@ -28,7 +28,7 @@ const (
// showPgConfig fetches Postgres configuration settings and opens it in $PAGER program.
func showPgConfig(db *postgres.DB, uiExit chan int) func(g *gocui.Gui, _ *gocui.View) error {
return func(g *gocui.Gui, _ *gocui.View) error {
res, err := stat.NewPGresult(db, query.GetAllSettings)
res, err := stat.NewPGresultQuery(db, query.GetAllSettings)
if err != nil {
printCmdline(g, err.Error())
return nil
Expand Down

0 comments on commit 390bc13

Please sign in to comment.