Merge pull request #265 from sosedoff/connection-usage

Record last query timestamp
This commit is contained in:
Dan Sosedoff 2017-09-15 17:03:31 -05:00 committed by GitHub
commit 206416889c

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 {