Add /api/schemas endpoint to list all database schemas
This commit is contained in:
parent
786081aafa
commit
f0552ab72d
12
api.go
12
api.go
@ -55,6 +55,7 @@ func setupRoutes(router *gin.Engine) {
|
||||
api.GET("/databases", API_GetDatabases)
|
||||
api.GET("/connection", API_ConnectionInfo)
|
||||
api.GET("/activity", API_Activity)
|
||||
api.GET("/schemas", API_GetSchemas)
|
||||
api.GET("/tables", API_GetTables)
|
||||
api.GET("/tables/:table", API_GetTable)
|
||||
api.GET("/tables/:table/rows", API_GetTableRows)
|
||||
@ -189,6 +190,17 @@ func API_ExplainQuery(c *gin.Context) {
|
||||
API_HandleQuery(fmt.Sprintf("EXPLAIN ANALYZE %s", query), c)
|
||||
}
|
||||
|
||||
func API_GetSchemas(c *gin.Context) {
|
||||
names, err := dbClient.Schemas()
|
||||
|
||||
if err != nil {
|
||||
c.JSON(400, NewError(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, names)
|
||||
}
|
||||
|
||||
func API_GetTables(c *gin.Context) {
|
||||
names, err := dbClient.Tables()
|
||||
|
||||
|
@ -87,6 +87,10 @@ func (client *Client) Databases() ([]string, error) {
|
||||
return client.fetchRows(PG_DATABASES)
|
||||
}
|
||||
|
||||
func (client *Client) Schemas() ([]string, error) {
|
||||
return client.fetchRows(PG_SCHEMAS)
|
||||
}
|
||||
|
||||
func (client *Client) Tables() ([]string, error) {
|
||||
return client.fetchRows(PG_TABLES)
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package main
|
||||
const (
|
||||
PG_DATABASES = `SELECT datname FROM pg_database WHERE NOT datistemplate ORDER BY datname ASC`
|
||||
|
||||
PG_SCHEMAS = `SELECT schema_name FROM information_schema.schemata ORDER BY schema_name ASC`
|
||||
|
||||
PG_INFO = `SELECT
|
||||
session_user
|
||||
, current_user
|
||||
|
Loading…
x
Reference in New Issue
Block a user