Files
inventory-plus-plus/database.go
T

24 lines
507 B
Go

package main
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
func newPool(ctx context.Context) (*pgxpool.Pool, error) {
pool, err := pgxpool.New(ctx, "postgres://app_client:app_password@localhost:5432/inventory_2?sslmode=disable")
if err != nil {
return nil, fmt.Errorf("failed to create database client: %w", err)
}
conn, err := pool.Acquire(ctx)
if err != nil {
return nil, fmt.Errorf("failed to create a database connection: %w", err)
}
conn.Release()
return pool, nil
}