Add example

pull/483/head
Jack Christensen 2019-01-05 18:47:50 -06:00
parent 14172b138b
commit f02ad34d66
1 changed files with 26 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package pgconn_test
import (
"context"
"crypto/tls"
"fmt"
"log"
"net"
"os"
"testing"
@ -513,3 +515,27 @@ end$$;`)
ensureConnValid(t, pgConn)
}
func Example() {
pgConn, err := pgconn.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE"))
if err != nil {
log.Fatalln(err)
}
defer pgConn.Close(context.Background())
result := pgConn.ExecParams(context.Background(), "select generate_series(1,3)", nil, nil, nil, nil).Read()
if result.Err != nil {
log.Fatalln(result.Err)
}
for _, row := range result.Rows {
fmt.Println(string(row[0]))
}
fmt.Println(result.CommandTag)
// Output:
// 1
// 2
// 3
// SELECT 3
}