Updated Getting started with pgx (markdown)

Jack Christensen 2021-05-31 07:12:42 -05:00
parent 4820f2e4a9
commit 4bc45cca9d

@ -44,6 +44,13 @@ $ go mod init hello
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
```
## Hello world from PostgreSQL
Create the file `main.go` and copy and paste the following:
@ -89,13 +96,6 @@ $ go run main.go
Hello, world!
```
You may see some output from Go when it downloads pgx for the first time.
```
go: finding module for package github.com/jackc/pgx/v4
go: found github.com/jackc/pgx/v4 in github.com/jackc/pgx/v4 v4.6.0
```
## 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()`.