feat: add PostgreSQL persistence layer with Neon DB support

This commit is contained in:
user
2026-04-27 12:35:03 +09:00
parent 01d102f5ef
commit bfdc7399eb
12 changed files with 671 additions and 6 deletions

29
internal/db/db.go Normal file
View File

@@ -0,0 +1,29 @@
package db
import (
"context"
"fmt"
"time"
"github.com/jackc/pgx/v5/pgxpool"
)
func Open(databaseURL string) (*pgxpool.Pool, error) {
if databaseURL == "" {
return nil, fmt.Errorf("database URL is required")
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
pool, err := pgxpool.New(ctx, databaseURL)
if err != nil {
return nil, fmt.Errorf("create connection pool: %w", err)
}
if err := pool.Ping(ctx); err != nil {
return nil, fmt.Errorf("ping database: %w", err)
}
return pool, nil
}