Skip to content

Commit 85e64da

Browse files
authored
mention pgxpool in go and pgx guide (#4047)
1 parent e81b1b5 commit 85e64da

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/guides/using-go-and-pgx.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,25 @@ pgx types directly.
109109
110110
fmt.Println(author.Name)
111111
}
112+
113+
.. note::
114+
For production applications, consider using pgxpool for connection pooling:
115+
116+
.. code-block:: go
117+
118+
import (
119+
"github.com/jackc/pgx/v5/pgxpool"
120+
"example.com/sqlc-tutorial/db"
121+
)
122+
123+
func main() {
124+
pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL"))
125+
if err != nil {
126+
fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err)
127+
os.Exit(1)
128+
}
129+
defer pool.Close()
130+
131+
q := db.New(pool)
132+
// Use q the same way as with single connections
133+
}

0 commit comments

Comments
 (0)