Set server version for the client on start up

This commit is contained in:
Dan Sosedoff 2017-03-10 22:48:23 -06:00
parent 1ee02d1451
commit e9787440fb

View File

@ -19,6 +19,7 @@ import (
type Client struct { type Client struct {
db *sqlx.DB db *sqlx.DB
tunnel *Tunnel tunnel *Tunnel
serverVersion string
History []history.Record `json:"history"` History []history.Record `json:"history"`
ConnectionString string `json:"connection_string"` ConnectionString string `json:"connection_string"`
} }
@ -62,6 +63,7 @@ func New() (*Client, error) {
History: history.New(), History: history.New(),
} }
client.setServerVersion()
return &client, nil return &client, nil
} }
@ -113,9 +115,20 @@ func NewFromUrl(url string, sshInfo *shared.SSHInfo) (*Client, error) {
History: history.New(), History: history.New(),
} }
client.setServerVersion()
return &client, nil return &client, nil
} }
func (client *Client) setServerVersion() {
res, err := client.query("SELECT version()")
if err != nil || len(res.Rows) < 1 {
return
}
version := res.Rows[0][0].(string)
client.serverVersion = strings.Split(version, " ")[1]
}
func (client *Client) Test() error { func (client *Client) Test() error {
return client.db.Ping() return client.db.Ping()
} }