doc.go 1016 B

123456789101112131415161718192021222324252627
  1. // Package pgxpool is a concurrency-safe connection pool for pgx.
  2. /*
  3. pgxpool implements a nearly identical interface to pgx connections.
  4. Creating a Pool
  5. The primary way of creating a pool is with [pgxpool.New]:
  6. pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL"))
  7. The database connection string can be in URL or keyword/value format. PostgreSQL settings, pgx settings, and pool settings can be
  8. specified here. In addition, a config struct can be created by [ParseConfig].
  9. config, err := pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))
  10. if err != nil {
  11. // ...
  12. }
  13. config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
  14. // do something with every new connection
  15. }
  16. pool, err := pgxpool.NewWithConfig(context.Background(), config)
  17. A pool returns without waiting for any connections to be established. Acquire a connection immediately after creating
  18. the pool to check if a connection can successfully be established.
  19. */
  20. package pgxpool