Move query history slice into client struct
This commit is contained in:
parent
7317bc2f7d
commit
8b3dd2563a
3
api.go
3
api.go
@ -19,7 +19,6 @@ func API_RunQuery(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
history = append(history, query)
|
|
||||||
API_HandleQuery(query, c)
|
API_HandleQuery(query, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ func API_GetTable(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func API_History(c *gin.Context) {
|
func API_History(c *gin.Context) {
|
||||||
c.JSON(200, history)
|
c.JSON(200, dbClient.history)
|
||||||
}
|
}
|
||||||
|
|
||||||
func API_Info(c *gin.Context) {
|
func API_Info(c *gin.Context) {
|
||||||
|
@ -15,7 +15,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
|
history []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
@ -37,6 +38,10 @@ func NewClient() (*Client, error) {
|
|||||||
return &Client{db: db}, nil
|
return &Client{db: db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) recordQuery(query string) {
|
||||||
|
client.history = append(client.history, query)
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) Tables() ([]string, error) {
|
func (client *Client) Tables() ([]string, error) {
|
||||||
res, err := client.Query(SQL_TABLES)
|
res, err := client.Query(SQL_TABLES)
|
||||||
|
|
||||||
@ -56,6 +61,8 @@ func (client *Client) Tables() ([]string, error) {
|
|||||||
func (client *Client) Query(query string) (*Result, error) {
|
func (client *Client) Query(query string) (*Result, error) {
|
||||||
rows, err := client.db.Queryx(query)
|
rows, err := client.db.Queryx(query)
|
||||||
|
|
||||||
|
client.recordQuery(query)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user