diff --git a/Getting-started-with-pgx.md b/Getting-started-with-pgx.md index 976d49c..86b2842 100644 --- a/Getting-started-with-pgx.md +++ b/Getting-started-with-pgx.md @@ -8,10 +8,10 @@ pgx requires a recent version of Go with module support. Use the `go version` co ``` $ go version -go version go1.16.4 darwin/amd64 +go version go1.19.1 darwin/amd64 ``` -The version should be at least 1.15. +The version should be at least 1.18. pgx also requires a PostgreSQL database that is accessible from your host. Use `psql` to test your connection. @@ -20,7 +20,7 @@ $ psql Timing is on. Null display is "∅". Line style is unicode. -psql (12.3) +psql (14.5 (Homebrew)) Type "help" for help. jack@[local]:5432 jack=# @@ -47,8 +47,8 @@ go: creating new go.mod: module hello Add pgx to your Go modules: ``` -$ go get github.com/jackc/pgx/v4 -go get: added github.com/jackc/pgx/v4 v4.11.0 +$ go get github.com/jackc/pgx/v5 + ``` ## Hello world from PostgreSQL @@ -98,7 +98,13 @@ Hello, world! ## Using a Connection Pool -The `*pgx.Conn` returned by `pgx.Connect()` represents a single connection and is not concurrency safe. This is entirely appropriate for a simple command line example such as above. However, for many uses, such as a web application server, concurrency is required. To use a connection pool replace the import `github.com/jackc/pgx/v4` with `github.com/jackc/pgx/v4/pgxpool` and connect with `pgxpool.Connect()` instead of `pgx.Connect()`. +The `*pgx.Conn` returned by `pgx.Connect()` represents a single connection and is not concurrency safe. This is entirely appropriate for a simple command line example such as above. However, for many uses, such as a web application server, concurrency is required. To use a connection pool replace the import `github.com/jackc/pgx/v5` with `github.com/jackc/pgx/v5/pgxpool` and connect with `pgxpool.Connect()` instead of `pgx.Connect()`. + +You may need to run `go get` for the `pgxpool` package. + +``` +$ go get github.com/jackc/pgx/v5/pgxpool +``` Here is the same program using the connection pool. @@ -110,13 +116,13 @@ import ( "fmt" "os" - "github.com/jackc/pgx/v4/pgxpool" + "github.com/jackc/pgx/v5/pgxpool" ) func main() { - dbpool, err := pgxpool.Connect(context.Background(), os.Getenv("DATABASE_URL")) + dbpool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL")) if err != nil { - fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err) + fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err) os.Exit(1) } defer dbpool.Close()