go integration and wikipedia

This commit is contained in:
jlimolina 2026-03-28 18:30:07 +01:00
parent 47a252e339
commit ee90335b92
7828 changed files with 1307913 additions and 20807 deletions

View file

@ -0,0 +1,44 @@
package db
import (
"context"
"fmt"
"time"
"github.com/jackc/pgx/v5/pgxpool"
)
var Pool *pgxpool.Pool
func Connect(databaseURL string) error {
config, err := pgxpool.ParseConfig(databaseURL)
if err != nil {
return fmt.Errorf("failed to parse database URL: %w", err)
}
config.MaxConns = 25
config.MinConns = 5
config.MaxConnLifetime = time.Hour
config.MaxConnIdleTime = 30 * time.Minute
Pool, err = pgxpool.NewWithConfig(context.Background(), config)
if err != nil {
return fmt.Errorf("failed to create pool: %w", err)
}
if err = Pool.Ping(context.Background()); err != nil {
return fmt.Errorf("failed to ping database: %w", err)
}
return nil
}
func Close() {
if Pool != nil {
Pool.Close()
}
}
func GetPool() *pgxpool.Pool {
return Pool
}