Update the client last usage timestamp

This commit is contained in:
Dan Sosedoff
2017-09-14 00:16:40 -05:00
parent 3a9bb58646
commit 6ab30ed308

View File

@@ -5,6 +5,7 @@ import (
neturl "net/url" neturl "net/url"
"reflect" "reflect"
"strings" "strings"
"time"
_ "github.com/lib/pq" _ "github.com/lib/pq"
@@ -20,6 +21,7 @@ type Client struct {
db *sqlx.DB db *sqlx.DB
tunnel *Tunnel tunnel *Tunnel
serverVersion string serverVersion string
lastQueryTime time.Time
History []history.Record `json:"history"` History []history.Record `json:"history"`
ConnectionString string `json:"connection_string"` ConnectionString string `json:"connection_string"`
} }
@@ -265,6 +267,11 @@ func (client *Client) ServerVersion() string {
} }
func (client *Client) query(query string, args ...interface{}) (*Result, error) { func (client *Client) query(query string, args ...interface{}) (*Result, error) {
// Update the last usage time
defer func() {
client.lastQueryTime = time.Now().UTC()
}()
// We're going to force-set transaction mode on every query. // We're going to force-set transaction mode on every query.
// This is needed so that default mode could not be changed by user. // This is needed so that default mode could not be changed by user.
if command.Opts.ReadOnly { if command.Opts.ReadOnly {