Code cleanup; add make lint task

This commit is contained in:
Dan Sosedoff 2022-12-01 16:51:12 -06:00
parent dafda4a977
commit f9e376a117
No known key found for this signature in database
GPG Key ID: 26186197D282B164
3 changed files with 35 additions and 25 deletions

View File

@ -15,6 +15,7 @@ usage:
@echo "make release : Generate binaries for all supported OSes"
@echo "make test : Execute test suite"
@echo "make test-all : Execute test suite on multiple PG versions"
@echo "make lint : Execute code linter"
@echo "make clean : Remove all build files and reset assets"
@echo "make docker : Build docker image"
@echo "make docker-release : Build and tag docker image"

View File

@ -345,7 +345,7 @@ func GetTable(c *gin.Context) {
var res *client.Result
var err error
if c.Request.FormValue("type") == "materialized_view" {
if c.Request.FormValue("type") == client.ObjTypeMaterializedView {
res, err = DB(c).MaterializedView(c.Params.ByName("table"))
} else {
res, err = DB(c).Table(c.Params.ByName("table"))

View File

@ -13,27 +13,36 @@ import (
"github.com/sosedoff/pgweb/pkg/command"
)
type Row []interface{}
const (
ObjTypeTable = "table"
ObjTypeView = "view"
ObjTypeMaterializedView = "materialized_view"
ObjTypeSequence = "sequence"
)
type Pagination struct {
Rows int64 `json:"rows_count"`
Page int64 `json:"page"`
Pages int64 `json:"pages_count"`
PerPage int64 `json:"per_page"`
}
type (
Row []interface{}
type Result struct {
Pagination *Pagination `json:"pagination,omitempty"`
Columns []string `json:"columns"`
Rows []Row `json:"rows"`
}
Pagination struct {
Rows int64 `json:"rows_count"`
Page int64 `json:"page"`
Pages int64 `json:"pages_count"`
PerPage int64 `json:"per_page"`
}
type Objects struct {
Tables []string `json:"table"`
Views []string `json:"view"`
MaterializedViews []string `json:"materialized_view"`
Sequences []string `json:"sequence"`
}
Result struct {
Pagination *Pagination `json:"pagination,omitempty"`
Columns []string `json:"columns"`
Rows []Row `json:"rows"`
}
Objects struct {
Tables []string `json:"table"`
Views []string `json:"view"`
MaterializedViews []string `json:"materialized_view"`
Sequences []string `json:"sequence"`
}
)
// Due to big int number limitations in javascript, numbers should be encoded
// as strings so they could be properly loaded on the frontend.
@ -139,7 +148,7 @@ func ObjectsFromResult(res *Result) map[string]*Objects {
for _, row := range res.Rows {
schema := row[0].(string)
name := row[1].(string)
object_type := row[2].(string)
objectType := row[2].(string)
if objects[schema] == nil {
objects[schema] = &Objects{
@ -150,14 +159,14 @@ func ObjectsFromResult(res *Result) map[string]*Objects {
}
}
switch object_type {
case "table":
switch objectType {
case ObjTypeTable:
objects[schema].Tables = append(objects[schema].Tables, name)
case "view":
case ObjTypeView:
objects[schema].Views = append(objects[schema].Views, name)
case "materialized_view":
case ObjTypeMaterializedView:
objects[schema].MaterializedViews = append(objects[schema].MaterializedViews, name)
case "sequence":
case ObjTypeSequence:
objects[schema].Sequences = append(objects[schema].Sequences, name)
}
}