mirror of
https://github.com/jackc/pgx.git
synced 2025-09-04 19:37:10 +00:00
Updated Getting started with pgx (markdown)
parent
4820f2e4a9
commit
4bc45cca9d
@ -44,6 +44,13 @@ $ go mod init hello
|
|||||||
go: creating new go.mod: module 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
|
## Hello world from PostgreSQL
|
||||||
|
|
||||||
Create the file `main.go` and copy and paste the following:
|
Create the file `main.go` and copy and paste the following:
|
||||||
@ -89,13 +96,6 @@ $ go run main.go
|
|||||||
Hello, world!
|
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
|
## 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/v4` with `github.com/jackc/pgx/v4/pgxpool` and connect with `pgxpool.Connect()` instead of `pgx.Connect()`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user