Merge pull request #1 from cbandy/canned-queries

Expose all constant queries as Client functions
This commit is contained in:
Dan Sosedoff 2014-10-15 23:46:48 -05:00
commit 5164d5946e
2 changed files with 10 additions and 2 deletions

4
api.go
View File

@ -79,7 +79,7 @@ func API_GetTables(c *gin.Context) {
} }
func API_GetTable(c *gin.Context) { func API_GetTable(c *gin.Context) {
res, err := dbClient.Query(fmt.Sprintf(PG_TABLE_SCHEMA, c.Params.ByName("table"))) res, err := dbClient.Table(c.Params.ByName("table"))
if err != nil { if err != nil {
c.JSON(400, NewError(err)) c.JSON(400, NewError(err))
@ -94,7 +94,7 @@ func API_History(c *gin.Context) {
} }
func API_Info(c *gin.Context) { func API_Info(c *gin.Context) {
res, err := dbClient.Query(PG_INFO) res, err := dbClient.Info()
if err != nil { if err != nil {
c.JSON(400, NewError(err)) c.JSON(400, NewError(err))

View File

@ -48,6 +48,10 @@ func (client *Client) recordQuery(query string) {
client.history = append(client.history, query) client.history = append(client.history, query)
} }
func (client *Client) Info() (*Result, error) {
return client.Query(PG_INFO)
}
func (client *Client) Databases() ([]string, error) { func (client *Client) Databases() ([]string, error) {
res, err := client.Query(PG_DATABASES) res, err := client.Query(PG_DATABASES)
@ -80,6 +84,10 @@ func (client *Client) Tables() ([]string, error) {
return tables, nil return tables, nil
} }
func (client *Client) Table(table string) (*Result, error) {
return client.Query(fmt.Sprintf(PG_TABLE_SCHEMA, table))
}
func (client *Client) TableIndexes(table string) (*Result, error) { func (client *Client) TableIndexes(table string) (*Result, error) {
res, err := client.Query(fmt.Sprintf(PG_TABLE_INDEXES, table)) res, err := client.Query(fmt.Sprintf(PG_TABLE_INDEXES, table))