Use db.Ping to test connection
This commit is contained in:
parent
ba74d8193c
commit
7d7e67a54e
@ -39,6 +39,10 @@ func NewClient() (*Client, error) {
|
|||||||
return &Client{db: db}, nil
|
return &Client{db: db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) Test() error {
|
||||||
|
return client.db.Ping()
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) recordQuery(query string) {
|
func (client *Client) recordQuery(query string) {
|
||||||
client.history = append(client.history, query)
|
client.history = append(client.history, query)
|
||||||
}
|
}
|
||||||
|
15
main.go
15
main.go
@ -10,10 +10,10 @@ import (
|
|||||||
|
|
||||||
var options struct {
|
var options struct {
|
||||||
Url string `long:"url" description:"Database connection string"`
|
Url string `long:"url" description:"Database connection string"`
|
||||||
Host string `short:"h" long:"host" description:"Server hostname or IP" default:"localhost"`
|
Host string `long:"host" description:"Server hostname or IP" default:"localhost"`
|
||||||
Port int `short:"p" long:"port" description:"Server port" default:"5432"`
|
Port int `long:"port" description:"Server port" default:"5432"`
|
||||||
User string `short:"u" long:"user" description:"Database user" default:"postgres"`
|
User string `long:"user" description:"Database user" default:"postgres"`
|
||||||
DbName string `short:"d" long:"db" description:"Database name" default:"postgres"`
|
DbName string `long:"db" description:"Database name" default:"postgres"`
|
||||||
Ssl string `long:"ssl" description:"SSL option" default:"disable"`
|
Ssl string `long:"ssl" description:"SSL option" default:"disable"`
|
||||||
Static string `short:"s" description:"Path to static assets" default:"./static"`
|
Static string `short:"s" description:"Path to static assets" default:"./static"`
|
||||||
}
|
}
|
||||||
@ -39,19 +39,18 @@ func getConnectionString() string {
|
|||||||
|
|
||||||
func initClient() {
|
func initClient() {
|
||||||
client, err := NewClient()
|
client, err := NewClient()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitWithMessage(err.Error())
|
exitWithMessage(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Query(SQL_INFO)
|
fmt.Println("Connecting to server...")
|
||||||
|
err = client.Test()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitWithMessage(err.Error())
|
exitWithMessage(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Checking tables...")
|
||||||
tables, err := client.Tables()
|
tables, err := client.Tables()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitWithMessage(err.Error())
|
exitWithMessage(err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user