Code cleanup; add make lint task
This commit is contained in:
parent
dafda4a977
commit
f9e376a117
1
Makefile
1
Makefile
@ -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"
|
||||
|
@ -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"))
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user